dpt_eisa.c revision 50477
1131087Smarcel/* 2131087Smarcel * Copyright (c) 1997 by Matthew N. Dodd <winter@jurai.net> 3131087Smarcel * All Rights Reserved 4131087Smarcel * 5131087Smarcel * Redistribution and use in source and binary forms, with or without 6131087Smarcel * modification, are permitted provided that the following conditions 7131087Smarcel * are met: 8131087Smarcel * 1. Redistributions of source code must retain the above copyright 9131087Smarcel * notice, this list of conditions, and the following disclaimer, 10131087Smarcel * without modification, immediately at the beginning of the file. 11131087Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12131087Smarcel * notice, this list of conditions and the following disclaimer in the 13131087Smarcel * documentation and/or other materials provided with the distribution. 14131087Smarcel * 3. The name of the author may not be used to endorse or promote products 15131087Smarcel * derived from this software without specific prior written permission. 16131087Smarcel * 17131087Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18131087Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19131087Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20131087Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21131087Smarcel * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22131087Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23131087Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24131087Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25131087Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26131087Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27131087Smarcel * SUCH DAMAGE. 28131087Smarcel */ 29131087Smarcel 30131087Smarcel/* 31131087Smarcel * Credits: Based on and part of the DPT driver for FreeBSD written and 32131087Smarcel * maintained by Simon Shapiro <shimon@simon-shapiro.org> 33131087Smarcel */ 34131087Smarcel 35131087Smarcel/* 36131087Smarcel * $FreeBSD: head/sys/dev/dpt/dpt_eisa.c 50477 1999-08-28 01:08:13Z peter $ 37131087Smarcel */ 38131087Smarcel 39131087Smarcel#include "eisa.h" 40131087Smarcel#if NEISA > 0 41131087Smarcel#include "opt_dpt.h" 42131087Smarcel 43131087Smarcel#include <sys/param.h> 44131087Smarcel#include <sys/systm.h> 45131087Smarcel#include <sys/malloc.h> 46131087Smarcel#include <sys/buf.h> 47131087Smarcel#include <sys/proc.h> 48131087Smarcel#include <sys/kernel.h> 49131087Smarcel#include <sys/module.h> 50131087Smarcel#include <sys/bus.h> 51131087Smarcel 52131087Smarcel#include <machine/bus_pio.h> 53131087Smarcel#include <machine/bus.h> 54131087Smarcel#include <machine/resource.h> 55131087Smarcel#include <sys/rman.h> 56131087Smarcel 57131087Smarcel#include <cam/scsi/scsi_all.h> 58131087Smarcel 59131087Smarcel#include <dev/dpt/dpt.h> 60131087Smarcel 61131087Smarcel#include <i386/eisa/eisaconf.h> 62131087Smarcel#include <i386/eisa/dpt_eisa.h> 63131087Smarcel 64131087Smarcel#include <machine/clock.h> 65131087Smarcel 66131087Smarcel#include <vm/vm.h> 67131087Smarcel#include <vm/vm_param.h> 68131087Smarcel#include <vm/pmap.h> 69131087Smarcel 70131087Smarcel/* Function Prototypes */ 71131087Smarcel 72131087Smarcelstatic const char *dpt_eisa_match(eisa_id_t); 73131087Smarcel 74131087Smarcelstatic int 75131087Smarceldpt_eisa_probe(device_t dev) 76131087Smarcel{ 77131087Smarcel const char *desc; 78131087Smarcel u_int32_t io_base; 79131087Smarcel u_int intdef; 80131087Smarcel u_int irq; 81131087Smarcel int shared; 82131087Smarcel 83131087Smarcel desc = dpt_eisa_match(eisa_get_id(dev)); 84131087Smarcel if (!desc) 85131087Smarcel return (ENXIO); 86131087Smarcel device_set_desc(dev, desc); 87131087Smarcel 88131087Smarcel io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE) 89131087Smarcel + DPT_EISA_SLOT_OFFSET; 90131087Smarcel 91131087Smarcel eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE); 92131087Smarcel 93131087Smarcel outb((DPT_EISA_CFENABLE + io_base), 0xf8); 94131087Smarcel 95131087Smarcel intdef = inb(DPT_EISA_INTDEF + io_base); 96131087Smarcel 97131087Smarcel irq = intdef & DPT_EISA_INT_NUM_MASK; 98131087Smarcel shared = (intdef & DPT_EISA_INT_LEVEL) 99131087Smarcel ? EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE; 100131087Smarcel switch (irq) { 101131087Smarcel case DPT_EISA_INT_NUM_11: 102131087Smarcel irq = 11; 103131087Smarcel break; 104131087Smarcel case DPT_EISA_INT_NUM_15: 105131087Smarcel irq = 15; 106131087Smarcel break; 107131087Smarcel case DPT_EISA_INT_NUM_14: 108131087Smarcel irq = 14; 109131087Smarcel break; 110131087Smarcel default: 111131087Smarcel device_printf(dev, "dpt at slot %d: illegal irq setting %d\n", 112131087Smarcel eisa_get_slot(dev), irq); 113131087Smarcel irq = 0; 114131087Smarcel break; 115131087Smarcel } 116131087Smarcel if (irq == 0) 117131087Smarcel return (ENXIO); 118131087Smarcel 119131087Smarcel eisa_add_intr(dev, irq, shared); 120131087Smarcel 121131087Smarcel return 0; 122131087Smarcel} 123131087Smarcel 124131087Smarcelstatic int 125131087Smarceldpt_eisa_attach(device_t dev) 126131087Smarcel{ 127131087Smarcel dpt_softc_t *dpt; 128131087Smarcel struct resource *io = 0; 129131087Smarcel struct resource *irq = 0; 130131087Smarcel int unit = device_get_unit(dev); 131131087Smarcel int s; 132131087Smarcel int rid; 133131087Smarcel void *ih; 134131087Smarcel 135131087Smarcel rid = 0; 136131087Smarcel io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 137131087Smarcel 0, ~0, 1, RF_ACTIVE); 138131087Smarcel if (!io) { 139131087Smarcel device_printf(dev, "No I/O space?!\n"); 140131087Smarcel return ENOMEM; 141131087Smarcel } 142131087Smarcel 143131087Smarcel dpt = dpt_alloc(unit, rman_get_bustag(io), 144131087Smarcel rman_get_bushandle(io) + DPT_EISA_EATA_REG_OFFSET); 145131087Smarcel if (dpt == NULL) 146131087Smarcel goto bad; 147131087Smarcel 148131087Smarcel /* Allocate a dmatag representing the capabilities of this attachment */ 149131087Smarcel /* XXX Should be a child of the EISA bus dma tag */ 150131087Smarcel if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0, 151131087Smarcel /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, 152131087Smarcel /*highaddr*/BUS_SPACE_MAXADDR, 153131087Smarcel /*filter*/NULL, /*filterarg*/NULL, 154131087Smarcel /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, 155131087Smarcel /*nsegments*/BUS_SPACE_UNRESTRICTED, 156131087Smarcel /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 157131087Smarcel /*flags*/0, &dpt->parent_dmat) != 0) { 158131087Smarcel dpt_free(dpt); 159131087Smarcel goto bad; 160131087Smarcel } 161131087Smarcel 162131087Smarcel rid = 0; 163131087Smarcel irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 164131087Smarcel 0, ~0, 1, RF_ACTIVE); 165131087Smarcel if (!irq) { 166131087Smarcel device_printf(dev, "No irq?!\n"); 167131087Smarcel goto bad; 168131087Smarcel } 169131087Smarcel 170131087Smarcel s = splcam(); 171131087Smarcel if (dpt_init(dpt) != 0) { 172131087Smarcel dpt_free(dpt); 173131087Smarcel goto bad; 174131087Smarcel } 175131087Smarcel 176131087Smarcel /* Register with the XPT */ 177138383Smarcel dpt_attach(dpt); 178131087Smarcel bus_setup_intr(dev, irq, INTR_TYPE_CAM, dpt_intr, dpt, &ih); 179138383Smarcel 180131087Smarcel splx(s); 181131087Smarcel 182131087Smarcel return 0; 183131087Smarcel 184131087Smarcel bad: 185131087Smarcel if (io) 186131087Smarcel bus_release_resource(dev, SYS_RES_IOPORT, 0, io); 187131087Smarcel if (irq) 188131087Smarcel bus_release_resource(dev, SYS_RES_IRQ, 0, irq); 189131087Smarcel return -1; 190131087Smarcel} 191131087Smarcel 192131087Smarcelstatic const char * 193131087Smarceldpt_eisa_match(type) 194131087Smarcel eisa_id_t type; 195131087Smarcel{ 196131087Smarcel switch (type) { 197131087Smarcel case DPT_EISA_DPT2402 : 198131087Smarcel return ("DPT PM2012A/9X"); 199131087Smarcel break; 200131087Smarcel case DPT_EISA_DPTA401 : 201131087Smarcel return ("DPT PM2012B/9X"); 202131087Smarcel break; 203131087Smarcel case DPT_EISA_DPTA402 : 204131087Smarcel return ("DPT PM2012B2/9X"); 205131087Smarcel break; 206131087Smarcel case DPT_EISA_DPTA410 : 207131087Smarcel return ("DPT PM2x22A/9X"); 208131087Smarcel break; 209131087Smarcel case DPT_EISA_DPTA411 : 210131087Smarcel return ("DPT Spectre"); 211131087Smarcel break; 212131087Smarcel case DPT_EISA_DPTA412 : 213131087Smarcel return ("DPT PM2021A/9X"); 214131087Smarcel break; 215131087Smarcel case DPT_EISA_DPTA420 : 216131087Smarcel return ("DPT Smart Cache IV (PM2042)"); 217131087Smarcel break; 218131087Smarcel case DPT_EISA_DPTA501 : 219131087Smarcel return ("DPT PM2012B1/9X"); 220131087Smarcel break; 221131087Smarcel case DPT_EISA_DPTA502 : 222131087Smarcel return ("DPT PM2012Bx/9X"); 223131087Smarcel break; 224131087Smarcel case DPT_EISA_DPTA701 : 225131087Smarcel return ("DPT PM2011B1/9X"); 226131087Smarcel break; 227131087Smarcel case DPT_EISA_DPTBC01 : 228131087Smarcel return ("DPT PM3011/7X ESDI"); 229131087Smarcel break; 230131087Smarcel case DPT_EISA_NEC8200 : 231131087Smarcel return ("NEC EATA SCSI"); 232131087Smarcel break; 233131087Smarcel case DPT_EISA_ATT2408 : 234131087Smarcel return ("ATT EATA SCSI"); 235131087Smarcel break; 236131087Smarcel default: 237131087Smarcel break; 238131087Smarcel } 239131087Smarcel 240131087Smarcel return (NULL); 241131087Smarcel} 242131087Smarcel 243131087Smarcelstatic device_method_t dpt_eisa_methods[] = { 244131087Smarcel /* Device interface */ 245131087Smarcel DEVMETHOD(device_probe, dpt_eisa_probe), 246131087Smarcel DEVMETHOD(device_attach, dpt_eisa_attach), 247131087Smarcel 248131087Smarcel { 0, 0 } 249131087Smarcel}; 250131087Smarcel 251131087Smarcelstatic driver_t dpt_eisa_driver = { 252131087Smarcel "dpt", 253131087Smarcel dpt_eisa_methods, 254131087Smarcel 1, /* unused */ 255131087Smarcel}; 256131087Smarcel 257131087Smarcelstatic devclass_t dpt_devclass; 258131087Smarcel 259131087SmarcelDRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0); 260131087Smarcel 261131087Smarcel#endif /* NEISA > 0 */ 262131087Smarcel