dpt_eisa.c revision 45791
1/* 2 * Copyright (c) 1997 by Matthew N. Dodd <winter@jurai.net> 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 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30/* 31 * Credits: Based on and part of the DPT driver for FreeBSD written and 32 * maintained by Simon Shapiro <shimon@simon-shapiro.org> 33 */ 34 35/* 36 * $Id: dpt_eisa.c,v 1.4 1998/09/15 08:33:35 gibbs Exp $ 37 */ 38 39#include "eisa.h" 40#if NEISA > 0 41#include "opt_dpt.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/malloc.h> 46#include <sys/buf.h> 47#include <sys/proc.h> 48#include <sys/kernel.h> 49#include <sys/module.h> 50#include <sys/bus.h> 51 52#include <machine/bus_pio.h> 53#include <machine/bus.h> 54#include <machine/resource.h> 55#include <sys/rman.h> 56 57#include <cam/scsi/scsi_all.h> 58 59#include <dev/dpt/dpt.h> 60 61#include <i386/eisa/eisaconf.h> 62#include <i386/eisa/dpt_eisa.h> 63 64#include <machine/clock.h> 65 66#include <vm/vm.h> 67#include <vm/vm_param.h> 68#include <vm/pmap.h> 69 70/* Function Prototypes */ 71 72static const char *dpt_eisa_match(eisa_id_t); 73 74static int 75dpt_eisa_probe(device_t dev) 76{ 77 const char *desc; 78 u_int32_t io_base; 79 u_int intdef; 80 u_int irq; 81 82 desc = dpt_eisa_match(eisa_get_id(dev)); 83 if (!desc) 84 return (ENXIO); 85 device_set_desc(dev, desc); 86 87 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE) 88 + DPT_EISA_SLOT_OFFSET; 89 90 eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE); 91 92 intdef = inb(DPT_EISA_INTDEF + io_base); 93 94 irq = intdef & DPT_EISA_INT_NUM_MASK; 95 switch (irq) { 96 case DPT_EISA_INT_NUM_11: 97 irq = 11; 98 break; 99 case DPT_EISA_INT_NUM_15: 100 irq = 15; 101 break; 102 case DPT_EISA_INT_NUM_14: 103 irq = 14; 104 break; 105 default: 106 printf("dpt at slot %d: illegal irq setting %d\n", 107 eisa_get_slot(dev), irq); 108 irq = 0; 109 break; 110 } 111 if (irq == 0) 112 return ENXIO; 113 114 eisa_add_intr(dev, irq); 115 116 return 0; 117} 118 119static int 120dpt_eisa_attach(device_t dev) 121{ 122 dpt_softc_t *dpt; 123 struct resource *io = 0; 124 struct resource *irq = 0; 125 int unit = device_get_unit(dev); 126 int shared; 127 int s; 128 int rid; 129 void *ih; 130 131 rid = 0; 132 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 133 0, ~0, 1, RF_ACTIVE); 134 if (!io) { 135 device_printf(dev, "No I/O space?!\n"); 136 return ENOMEM; 137 } 138 139 shared = (inb(DPT_EISA_INTDEF + rman_get_start(io)) 140 & DPT_EISA_INT_LEVEL) ? RF_SHAREABLE : 0; 141 142 dpt = dpt_alloc(unit, rman_get_bustag(io), 143 rman_get_bushandle(io) + DPT_EISA_EATA_REG_OFFSET); 144 if (dpt == NULL) 145 goto bad; 146 147 /* Allocate a dmatag representing the capabilities of this attachment */ 148 /* XXX Should be a child of the EISA bus dma tag */ 149 if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/0, /*boundary*/0, 150 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, 151 /*highaddr*/BUS_SPACE_MAXADDR, 152 /*filter*/NULL, /*filterarg*/NULL, 153 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, 154 /*nsegments*/BUS_SPACE_UNRESTRICTED, 155 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 156 /*flags*/0, &dpt->parent_dmat) != 0) { 157 dpt_free(dpt); 158 goto bad; 159 } 160 161 rid = 0; 162 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 163 0, ~0, 1, shared | RF_ACTIVE); 164 if (!irq) { 165 device_printf(dev, "No irq?!\n"); 166 goto bad; 167 } 168 169 s = splcam(); 170 if (dpt_init(dpt) != 0) { 171 dpt_free(dpt); 172 goto bad; 173 } 174 175 /* Register with the XPT */ 176 dpt_attach(dpt); 177 bus_setup_intr(dev, irq, dpt_intr, dpt, &ih); 178 179 splx(s); 180 181 return 0; 182 183 bad: 184 if (io) 185 bus_release_resource(dev, SYS_RES_IOPORT, 0, io); 186 if (irq) 187 bus_release_resource(dev, SYS_RES_IRQ, 0, irq); 188 return -1; 189} 190 191static const char * 192dpt_eisa_match(type) 193 eisa_id_t type; 194{ 195 switch (type) { 196 case DPT_EISA_DPT2402 : 197 return ("DPT PM2012A/9X"); 198 break; 199 case DPT_EISA_DPTA401 : 200 return ("DPT PM2012B/9X"); 201 break; 202 case DPT_EISA_DPTA402 : 203 return ("DPT PM2012B2/9X"); 204 break; 205 case DPT_EISA_DPTA410 : 206 return ("DPT PM2x22A/9X"); 207 break; 208 case DPT_EISA_DPTA411 : 209 return ("DPT Spectre"); 210 break; 211 case DPT_EISA_DPTA412 : 212 return ("DPT PM2021A/9X"); 213 break; 214 case DPT_EISA_DPTA420 : 215 return ("DPT Smart Cache IV (PM2042)"); 216 break; 217 case DPT_EISA_DPTA501 : 218 return ("DPT PM2012B1/9X"); 219 break; 220 case DPT_EISA_DPTA502 : 221 return ("DPT PM2012Bx/9X"); 222 break; 223 case DPT_EISA_DPTA701 : 224 return ("DPT PM2011B1/9X"); 225 break; 226 case DPT_EISA_DPTBC01 : 227 return ("DPT PM3011/7X ESDI"); 228 break; 229 case DPT_EISA_NEC8200 : 230 return ("NEC EATA SCSI"); 231 break; 232 case DPT_EISA_ATT2408 : 233 return ("ATT EATA SCSI"); 234 break; 235 default: 236 break; 237 } 238 239 return (NULL); 240} 241 242static device_method_t dpt_eisa_methods[] = { 243 /* Device interface */ 244 DEVMETHOD(device_probe, dpt_eisa_probe), 245 DEVMETHOD(device_attach, dpt_eisa_attach), 246 247 { 0, 0 } 248}; 249 250static driver_t dpt_eisa_driver = { 251 "dpt", 252 dpt_eisa_methods, 253 DRIVER_TYPE_CAM, 254 1, /* unused */ 255}; 256 257static devclass_t dpt_devclass; 258 259DRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0); 260 261#endif /* NEISA > 0 */ 262