dpt_eisa.c revision 117126
1/*- 2 * Copyright (c) 1997, 2000 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 * 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/dpt/dpt_eisa.c 117126 2003-07-01 15:52:06Z scottl $ 27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/module.h> 33#include <sys/lock.h> 34#include <sys/mutex.h> 35#include <sys/bus.h> 36 37#include <machine/bus_pio.h> 38#include <machine/bus.h> 39#include <machine/resource.h> 40#include <sys/rman.h> 41 42#include <dev/eisa/eisaconf.h> 43 44#include <cam/scsi/scsi_all.h> 45 46#include <dev/dpt/dpt.h> 47 48#define DPT_EISA_IOSIZE 0x9 49#define DPT_EISA_SLOT_OFFSET 0x0c00 50#define DPT_EISA_EATA_REG_OFFSET 0x0088 51 52#define DPT_EISA_DPT2402 0x12142402 /* DPT PM2012A/9X */ 53#define DPT_EISA_DPTA401 0x1214A401 /* DPT PM2012B/9X */ 54#define DPT_EISA_DPTA402 0x1214A402 /* DPT PM2012B2/9X */ 55#define DPT_EISA_DPTA410 0x1214A410 /* DPT PM2x22A/9X */ 56#define DPT_EISA_DPTA411 0x1214A411 /* DPT Spectre */ 57#define DPT_EISA_DPTA412 0x1214A412 /* DPT PM2021A/9X */ 58#define DPT_EISA_DPTA420 0x1214A420 /* DPT Smart Cache IV (PM2042) */ 59#define DPT_EISA_DPTA501 0x1214A501 /* DPT PM2012B1/9X" */ 60#define DPT_EISA_DPTA502 0x1214A502 /* DPT PM2012Bx/9X */ 61#define DPT_EISA_DPTA701 0x1214A701 /* DPT PM2011B1/9X */ 62#define DPT_EISA_DPTBC01 0x1214BC01 /* DPT PM3011/7X ESDI */ 63#define DPT_EISA_DPT8200 0x12148200 /* NEC EATA SCSI */ 64#define DPT_EISA_DPT2408 0x12142408 /* ATT EATA SCSI */ 65 66/* Function Prototypes */ 67 68static const char * dpt_eisa_match (eisa_id_t); 69static int dpt_eisa_probe (device_t); 70static int dpt_eisa_attach (device_t); 71 72static int 73dpt_eisa_probe (device_t dev) 74{ 75 const char * desc; 76 u_int32_t io_base; 77 dpt_conf_t * conf; 78 79 desc = dpt_eisa_match(eisa_get_id(dev)); 80 if (!desc) 81 return (ENXIO); 82 device_set_desc(dev, desc); 83 84 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + 85 DPT_EISA_SLOT_OFFSET + 86 DPT_EISA_EATA_REG_OFFSET; 87 88 conf = dpt_pio_get_conf(io_base); 89 if (!conf) { 90 printf("dpt: dpt_pio_get_conf() failed.\n"); 91 return (ENXIO); 92 } 93 94 eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE); 95 eisa_add_intr(dev, conf->IRQ, 96 (conf->IRQ_TR ? EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE)); 97 98 return 0; 99} 100 101static int 102dpt_eisa_attach (device_t dev) 103{ 104 dpt_softc_t * dpt; 105 int s; 106 int error = 0; 107 108 dpt = device_get_softc(dev); 109 110 dpt->io_rid = 0; 111 dpt->io_type = SYS_RES_IOPORT; 112 dpt->irq_rid = 0; 113 114 error = dpt_alloc_resources(dev); 115 if (error) { 116 goto bad; 117 } 118 119 dpt_alloc(dev); 120 121 /* Allocate a dmatag representing the capabilities of this attachment */ 122 /* XXX Should be a child of the EISA bus dma tag */ 123 if (bus_dma_tag_create( /* parent */ NULL, 124 /* alignemnt */ 1, 125 /* boundary */ 0, 126 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, 127 /* highaddr */ BUS_SPACE_MAXADDR, 128 /* filter */ NULL, 129 /* filterarg */ NULL, 130 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT, 131 /* nsegments */ ~0, 132 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, 133 /* flags */ 0, 134 /* lockfunc */ busdma_lock_mutex, 135 /* lockarg */ &Giant, 136 &dpt->parent_dmat) != 0) { 137 error = ENXIO; 138 goto bad; 139 } 140 141 s = splcam(); 142 143 if (dpt_init(dpt) != 0) { 144 splx(s); 145 error = ENXIO; 146 goto bad; 147 } 148 149 /* Register with the XPT */ 150 dpt_attach(dpt); 151 152 splx(s); 153 154 if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, 155 dpt_intr, dpt, &dpt->ih)) { 156 device_printf(dev, "Unable to register interrupt handler\n"); 157 error = ENXIO; 158 goto bad; 159 } 160 161 return (error); 162 163 bad: 164 dpt_release_resources(dev); 165 166 if (dpt) 167 dpt_free(dpt); 168 169 return (error); 170} 171 172static const char * 173dpt_eisa_match(type) 174 eisa_id_t type; 175{ 176 switch (type) { 177 case DPT_EISA_DPT2402: 178 case DPT_EISA_DPTA401: 179 case DPT_EISA_DPTA402: 180 case DPT_EISA_DPTA410: 181 case DPT_EISA_DPTA411: 182 case DPT_EISA_DPTA412: 183 case DPT_EISA_DPTA420: 184 case DPT_EISA_DPTA501: 185 case DPT_EISA_DPTA502: 186 case DPT_EISA_DPTA701: 187 case DPT_EISA_DPTBC01: 188 case DPT_EISA_DPT8200: 189 case DPT_EISA_DPT2408: 190 return ("DPT SCSI Host Bus Adapter"); 191 break; 192 default: 193 break; 194 } 195 196 return (NULL); 197} 198 199static device_method_t dpt_eisa_methods[] = { 200 /* Device interface */ 201 DEVMETHOD(device_probe, dpt_eisa_probe), 202 DEVMETHOD(device_attach, dpt_eisa_attach), 203 DEVMETHOD(device_detach, dpt_detach), 204 205 { 0, 0 } 206}; 207 208static driver_t dpt_eisa_driver = { 209 "dpt", 210 dpt_eisa_methods, 211 sizeof(dpt_softc_t), 212}; 213 214DRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0); 215