2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001,2002,2003 Søren Schmidt <sos@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
40 #include <sys/malloc.h>
42 #include <sys/mutex.h>
45 #include <machine/stdarg.h>
46 #include <machine/resource.h>
47 #include <machine/bus.h>
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcireg.h>
52 #include "dev/pst/pst-iop.h"
55 iop_pci_probe(device_t dev)
57 /* tested with actual hardware kindly donated by Promise */
58 if (pci_get_devid(dev) == 0x19628086 && pci_get_subvendor(dev) == 0x105a) {
59 device_set_desc(dev, "Promise SuperTrak SX6000 ATA RAID controller");
60 return BUS_PROBE_DEFAULT;
63 /* support the older SuperTrak 100 as well */
64 if (pci_get_devid(dev) == 0x19608086 && pci_get_subvendor(dev) == 0x105a) {
65 device_set_desc(dev, "Promise SuperTrak 100 ATA RAID controller");
66 return BUS_PROBE_DEFAULT;
73 iop_pci_attach(device_t dev)
75 struct iop_softc *sc = device_get_softc(dev);
81 bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
87 sc->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
88 RF_SHAREABLE | RF_ACTIVE);
90 /* now setup the infrastructure to talk to the device */
91 pci_enable_busmaster(dev);
93 sc->ibase = rman_get_virtual(sc->r_mem);
94 sc->reg = (struct i2o_registers *)sc->ibase;
96 mtx_init(&sc->mtx, "pst lock", NULL, MTX_DEF);
100 return bus_generic_attach(dev);
104 iop_pci_detach(device_t dev)
106 struct iop_softc *sc = device_get_softc(dev);
109 error = bus_generic_detach(dev);
112 bus_teardown_intr(dev, sc->r_irq, sc->handle);
113 bus_release_resource(dev, SYS_RES_IRQ, 0x00, sc->r_irq);
114 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), sc->r_mem);
115 mtx_destroy(&sc->mtx);
119 static device_method_t pst_pci_methods[] = {
120 DEVMETHOD(device_probe, iop_pci_probe),
121 DEVMETHOD(device_attach, iop_pci_attach),
122 DEVMETHOD(device_detach, iop_pci_detach),
126 static driver_t pst_pci_driver = {
129 sizeof(struct iop_softc),
132 static devclass_t pst_pci_devclass;
134 DRIVER_MODULE(pstpci, pci, pst_pci_driver, pst_pci_devclass, 0, 0);