2 * Product specific probe and attach routines for:
3 * Buslogic BT946, BT948, BT956, BT958 SCSI controllers
5 * Copyright (c) 1995, 1997, 1998 Justin T. Gibbs
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
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
29 * $FreeBSD: src/sys/dev/buslogic/bt_pci.c,v 1.11 2000/01/17 12:38:00 nyan Exp $
30 * $DragonFly: src/sys/dev/disk/buslogic/bt_pci.c,v 1.5 2006/10/25 20:55:53 dillon Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
38 #include <sys/thread2.h>
40 #include <bus/pci/pcireg.h>
41 #include <bus/pci/pcivar.h>
45 #define BT_PCI_IOADDR PCIR_MAPS
46 #define BT_PCI_MEMADDR PCIR_MAPS + 4
48 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040104Bul
49 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140104Bul
50 #define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130104Bul
53 bt_pci_alloc_resources(device_t dev)
55 int command, type = 0, rid, zero;
56 struct resource *regs = 0;
57 struct resource *irq = 0;
59 command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
61 /* XXX Memory Mapped I/O seems to cause problems */
62 if (command & PCIM_CMD_MEMEN) {
63 type = SYS_RES_MEMORY;
65 regs = bus_alloc_resource(dev, type, &rid,
69 if (!regs && (command & PCIM_CMD_PORTEN)) {
70 type = SYS_RES_IOPORT;
72 regs = bus_alloc_resource(dev, type, &rid,
80 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &zero,
81 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
83 bus_release_resource(dev, type, rid, regs);
87 bt_init_softc(dev, regs, irq, 0);
93 bt_pci_release_resources(device_t dev)
95 struct bt_softc *bt = device_get_softc(dev);
98 /* XXX can't cope with memory registers anyway */
99 bus_release_resource(dev, SYS_RES_IOPORT,
100 BT_PCI_IOADDR, bt->port);
102 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
107 bt_pci_probe(device_t dev)
109 switch (pci_get_devid(dev)) {
110 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER:
111 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC:
113 struct bt_softc *bt = device_get_softc(dev);
114 pci_info_data_t pci_info;
117 error = bt_pci_alloc_resources(dev);
122 * Determine if an ISA compatible I/O port has been
123 * enabled. If so, record the port so it will not
124 * be probed by our ISA probe. If the PCI I/O port
125 * was not set to the compatibility port, disable it.
127 error = bt_cmd(bt, BOP_INQUIRE_PCI_INFO,
128 /*param*/NULL, /*paramlen*/0,
129 (u_int8_t*)&pci_info, sizeof(pci_info),
130 DEFAULT_CMD_TIMEOUT);
132 && pci_info.io_port < BIO_DISABLED) {
133 bt_mark_probed_bio(pci_info.io_port);
134 if (rman_get_start(bt->port) !=
135 bt_iop_from_bio(pci_info.io_port)) {
138 new_addr = BIO_DISABLED;
139 bt_cmd(bt, BOP_MODIFY_IO_ADDR,
141 /*paramlen*/1, /*reply_buf*/NULL,
143 DEFAULT_CMD_TIMEOUT);
146 bt_pci_release_resources(dev);
147 device_set_desc(dev, "Buslogic Multi-Master SCSI Host Adapter");
158 bt_pci_attach(device_t dev)
160 struct bt_softc *bt = device_get_softc(dev);
163 /* Initialize softc */
164 error = bt_pci_alloc_resources(dev);
166 device_printf(dev, "can't allocate resources in bt_pci_attach\n");
170 /* Allocate a dmatag for our CCB DMA maps */
171 /* XXX Should be a child of the PCI bus dma tag */
172 if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
173 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
174 /*highaddr*/BUS_SPACE_MAXADDR,
175 /*filter*/NULL, /*filterarg*/NULL,
176 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
177 /*nsegments*/BUS_SPACE_UNRESTRICTED,
178 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
179 /*flags*/0, &bt->parent_dmat) != 0) {
180 bt_pci_release_resources(dev);
185 * Protect ourself from spurrious interrupts during
186 * intialization and attach. We should really rely
187 * on interrupts during attach, but we don't have
188 * access to our interrupts during ISA probes, so until
189 * that changes, we mask our interrupts during attach
194 if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
195 bt_pci_release_resources(dev);
200 error = bt_attach(dev);
204 bt_pci_release_resources(dev);
211 static device_method_t bt_pci_methods[] = {
212 /* Device interface */
213 DEVMETHOD(device_probe, bt_pci_probe),
214 DEVMETHOD(device_attach, bt_pci_attach),
219 static driver_t bt_pci_driver = {
222 sizeof(struct bt_softc),
225 static devclass_t bt_devclass;
227 DRIVER_MODULE(bt, pci, bt_pci_driver, bt_devclass, 0, 0);