127da7e6fSSøren Schmidt /*- 2718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3718cf2ccSPedro F. Giffuni * 49a14aa01SUlrich Spörlein * Copyright (c) 2001,2002,2003 Søren Schmidt <sos@FreeBSD.org> 527da7e6fSSøren Schmidt * All rights reserved. 627da7e6fSSøren Schmidt * 727da7e6fSSøren Schmidt * Redistribution and use in source and binary forms, with or without 827da7e6fSSøren Schmidt * modification, are permitted provided that the following conditions 927da7e6fSSøren Schmidt * are met: 1027da7e6fSSøren Schmidt * 1. Redistributions of source code must retain the above copyright 1127da7e6fSSøren Schmidt * notice, this list of conditions and the following disclaimer, 1227da7e6fSSøren Schmidt * without modification, immediately at the beginning of the file. 1327da7e6fSSøren Schmidt * 2. Redistributions in binary form must reproduce the above copyright 1427da7e6fSSøren Schmidt * notice, this list of conditions and the following disclaimer in the 1527da7e6fSSøren Schmidt * documentation and/or other materials provided with the distribution. 1627da7e6fSSøren Schmidt * 3. The name of the author may not be used to endorse or promote products 1727da7e6fSSøren Schmidt * derived from this software without specific prior written permission. 1827da7e6fSSøren Schmidt * 1927da7e6fSSøren Schmidt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2027da7e6fSSøren Schmidt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2127da7e6fSSøren Schmidt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2227da7e6fSSøren Schmidt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2327da7e6fSSøren Schmidt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2427da7e6fSSøren Schmidt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2527da7e6fSSøren Schmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2627da7e6fSSøren Schmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2727da7e6fSSøren Schmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2827da7e6fSSøren Schmidt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2927da7e6fSSøren Schmidt */ 3027da7e6fSSøren Schmidt 3127da7e6fSSøren Schmidt #include <sys/param.h> 3227da7e6fSSøren Schmidt #include <sys/systm.h> 3327da7e6fSSøren Schmidt #include <sys/kernel.h> 3427da7e6fSSøren Schmidt #include <sys/module.h> 3527da7e6fSSøren Schmidt #include <sys/bus.h> 3627da7e6fSSøren Schmidt #include <sys/bio.h> 3727da7e6fSSøren Schmidt #include <sys/malloc.h> 38ac9953bfSSøren Schmidt #include <sys/lock.h> 39ac9953bfSSøren Schmidt #include <sys/mutex.h> 4027da7e6fSSøren Schmidt #include <vm/vm.h> 4127da7e6fSSøren Schmidt #include <vm/pmap.h> 4227da7e6fSSøren Schmidt #include <machine/stdarg.h> 4327da7e6fSSøren Schmidt #include <machine/resource.h> 4427da7e6fSSøren Schmidt #include <machine/bus.h> 4527da7e6fSSøren Schmidt #include <sys/rman.h> 4638d8c994SWarner Losh #include <dev/pci/pcivar.h> 4738d8c994SWarner Losh #include <dev/pci/pcireg.h> 4827da7e6fSSøren Schmidt 4927da7e6fSSøren Schmidt #include "dev/pst/pst-iop.h" 5027da7e6fSSøren Schmidt 5127da7e6fSSøren Schmidt static int 5227da7e6fSSøren Schmidt iop_pci_probe(device_t dev) 5327da7e6fSSøren Schmidt { 5427da7e6fSSøren Schmidt /* tested with actual hardware kindly donated by Promise */ 5527da7e6fSSøren Schmidt if (pci_get_devid(dev) == 0x19628086 && pci_get_subvendor(dev) == 0x105a) { 5627da7e6fSSøren Schmidt device_set_desc(dev, "Promise SuperTrak SX6000 ATA RAID controller"); 576b9907e7SWarner Losh return BUS_PROBE_DEFAULT; 5827da7e6fSSøren Schmidt } 5927da7e6fSSøren Schmidt 6001ed3358SSøren Schmidt /* support the older SuperTrak 100 as well */ 6101ed3358SSøren Schmidt if (pci_get_devid(dev) == 0x19608086 && pci_get_subvendor(dev) == 0x105a) { 6227da7e6fSSøren Schmidt device_set_desc(dev, "Promise SuperTrak 100 ATA RAID controller"); 636b9907e7SWarner Losh return BUS_PROBE_DEFAULT; 6427da7e6fSSøren Schmidt } 6527da7e6fSSøren Schmidt 6627da7e6fSSøren Schmidt return ENXIO; 6727da7e6fSSøren Schmidt } 6827da7e6fSSøren Schmidt 6927da7e6fSSøren Schmidt static int 7027da7e6fSSøren Schmidt iop_pci_attach(device_t dev) 7127da7e6fSSøren Schmidt { 7227da7e6fSSøren Schmidt struct iop_softc *sc = device_get_softc(dev); 7327da7e6fSSøren Schmidt int rid; 7427da7e6fSSøren Schmidt 7527da7e6fSSøren Schmidt /* get resources */ 76369934d6SJohn Baldwin rid = PCIR_BAR(0); 7727da7e6fSSøren Schmidt sc->r_mem = 785f96beb9SNate Lawson bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); 7927da7e6fSSøren Schmidt 8027da7e6fSSøren Schmidt if (!sc->r_mem) 81369934d6SJohn Baldwin return ENXIO; 8227da7e6fSSøren Schmidt 8327da7e6fSSøren Schmidt rid = 0x00; 845f96beb9SNate Lawson sc->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 855f96beb9SNate Lawson RF_SHAREABLE | RF_ACTIVE); 8627da7e6fSSøren Schmidt 8727da7e6fSSøren Schmidt /* now setup the infrastructure to talk to the device */ 88c68534f1SScott Long pci_enable_busmaster(dev); 8927da7e6fSSøren Schmidt 9027da7e6fSSøren Schmidt sc->ibase = rman_get_virtual(sc->r_mem); 9127da7e6fSSøren Schmidt sc->reg = (struct i2o_registers *)sc->ibase; 9227da7e6fSSøren Schmidt sc->dev = dev; 93930a96e4SDon Lewis mtx_init(&sc->mtx, "pst lock", NULL, MTX_DEF); 9427da7e6fSSøren Schmidt 9527da7e6fSSøren Schmidt if (!iop_init(sc)) 9627da7e6fSSøren Schmidt return 0; 97*18250ec6SJohn Baldwin bus_attach_children(dev); 98*18250ec6SJohn Baldwin return (0); 9927da7e6fSSøren Schmidt } 10027da7e6fSSøren Schmidt 101ac9953bfSSøren Schmidt static int 102ac9953bfSSøren Schmidt iop_pci_detach(device_t dev) 103ac9953bfSSøren Schmidt { 104ac9953bfSSøren Schmidt struct iop_softc *sc = device_get_softc(dev); 105369934d6SJohn Baldwin int error; 106ac9953bfSSøren Schmidt 107369934d6SJohn Baldwin error = bus_generic_detach(dev); 108369934d6SJohn Baldwin if (error) 109369934d6SJohn Baldwin return (error); 110ac9953bfSSøren Schmidt bus_teardown_intr(dev, sc->r_irq, sc->handle); 111ac9953bfSSøren Schmidt bus_release_resource(dev, SYS_RES_IRQ, 0x00, sc->r_irq); 112369934d6SJohn Baldwin bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), sc->r_mem); 113369934d6SJohn Baldwin mtx_destroy(&sc->mtx); 114369934d6SJohn Baldwin return (0); 115ac9953bfSSøren Schmidt } 116ac9953bfSSøren Schmidt 11727da7e6fSSøren Schmidt static device_method_t pst_pci_methods[] = { 11827da7e6fSSøren Schmidt DEVMETHOD(device_probe, iop_pci_probe), 11927da7e6fSSøren Schmidt DEVMETHOD(device_attach, iop_pci_attach), 120ac9953bfSSøren Schmidt DEVMETHOD(device_detach, iop_pci_detach), 12127da7e6fSSøren Schmidt { 0, 0 } 12227da7e6fSSøren Schmidt }; 12327da7e6fSSøren Schmidt 12427da7e6fSSøren Schmidt static driver_t pst_pci_driver = { 12527da7e6fSSøren Schmidt "pstpci", 12627da7e6fSSøren Schmidt pst_pci_methods, 12727da7e6fSSøren Schmidt sizeof(struct iop_softc), 12827da7e6fSSøren Schmidt }; 12927da7e6fSSøren Schmidt 1309199ef40SJohn Baldwin DRIVER_MODULE(pstpci, pci, pst_pci_driver, 0, 0); 131