1 /*-
2 * Product specific probe and attach routines for:
3 * Buslogic BT946, BT948, BT956, BT958 SCSI controllers
4 *
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 *
7 * Copyright (c) 1995, 1997, 1998 Justin T. Gibbs
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD: releng/12.0/sys/dev/buslogic/bt_pci.c 326255 2017-11-27 14:52:40Z pfg $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/bus.h>
42
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45
46 #include <machine/bus.h>
47 #include <machine/resource.h>
48 #include <sys/rman.h>
49
50 #include <dev/buslogic/btreg.h>
51
52 #define BT_PCI_IOADDR PCIR_BAR(0)
53 #define BT_PCI_MEMADDR PCIR_BAR(1)
54
55 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040104Bul
56 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140104Bul
57 #define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130104Bul
58
59 static int
60 bt_pci_alloc_resources(device_t dev)
61 {
62 int type = 0, rid, zero;
63 struct resource *regs = NULL;
64 struct resource *irq = NULL;
65
66 #if 0
67 /* XXX Memory Mapped I/O seems to cause problems */
68 type = SYS_RES_MEMORY;
69 rid = BT_PCI_MEMADDR;
70 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
71 #else
72 type = SYS_RES_IOPORT;
73 rid = BT_PCI_IOADDR;
74 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
75 #endif
76 if (!regs)
77 return (ENOMEM);
78
79 zero = 0;
80 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
81 RF_ACTIVE | RF_SHAREABLE);
82 if (!irq) {
83 bus_release_resource(dev, type, rid, regs);
84 return (ENOMEM);
85 }
86
87 bt_init_softc(dev, regs, irq, 0);
88
89 return (0);
90 }
91
92 static void
93 bt_pci_release_resources(device_t dev)
94 {
95 struct bt_softc *bt = device_get_softc(dev);
96
97 if (bt->port)
98 /* XXX can't cope with memory registers anyway */
99 bus_release_resource(dev, SYS_RES_IOPORT,
100 BT_PCI_IOADDR, bt->port);
101 if (bt->irq)
102 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
103 bt_free_softc(dev);
104 }
105
106 static int
107 bt_pci_probe(device_t dev)
108 {
109 switch (pci_get_devid(dev)) {
110 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER:
111 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC:
112 {
113 struct bt_softc *bt = device_get_softc(dev);
114 pci_info_data_t pci_info;
115 int error;
116
117 error = bt_pci_alloc_resources(dev);
118 if (error)
119 return (error);
120
121 /*
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.
126 */
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);
131 if (error == 0
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)) {
136 u_int8_t new_addr;
137
138 new_addr = BIO_DISABLED;
139 bt_cmd(bt, BOP_MODIFY_IO_ADDR,
140 /*param*/&new_addr,
141 /*paramlen*/1, /*reply_buf*/NULL,
142 /*reply_len*/0,
143 DEFAULT_CMD_TIMEOUT);
144 }
145 }
146 bt_pci_release_resources(dev);
147 device_set_desc(dev, "Buslogic Multi-Master SCSI Host Adapter");
148 return (BUS_PROBE_DEFAULT);
149 }
150 default:
151 break;
152 }
153
154 return (ENXIO);
155 }
156
157 static int
158 bt_pci_attach(device_t dev)
159 {
160 struct bt_softc *bt = device_get_softc(dev);
161 int error;
162
163 /* Initialize softc */
164 error = bt_pci_alloc_resources(dev);
165 if (error) {
166 device_printf(dev, "can't allocate resources in bt_pci_attach\n");
167 return error;
168 }
169
170 /* Allocate a dmatag for our CCB DMA maps */
171 if (bus_dma_tag_create( /* PCI parent */ bus_get_dma_tag(dev),
172 /* alignemnt */ 1,
173 /* boundary */ 0,
174 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
175 /* highaddr */ BUS_SPACE_MAXADDR,
176 /* filter */ NULL,
177 /* filterarg */ NULL,
178 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
179 /* nsegments */ ~0,
180 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
181 /* flags */ 0,
182 /* lockfunc */ NULL,
183 /* lockarg */ NULL,
184 &bt->parent_dmat) != 0) {
185 bt_pci_release_resources(dev);
186 return (ENOMEM);
187 }
188
189 if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
190 bt_pci_release_resources(dev);
191 return (ENXIO);
192 }
193
194 error = bt_attach(dev);
195
196 if (error) {
197 bt_pci_release_resources(dev);
198 return (error);
199 }
200
201 return (0);
202 }
203
204 static device_method_t bt_pci_methods[] = {
205 /* Device interface */
206 DEVMETHOD(device_probe, bt_pci_probe),
207 DEVMETHOD(device_attach, bt_pci_attach),
208
209 { 0, 0 }
210 };
211
212 static driver_t bt_pci_driver = {
213 "bt",
214 bt_pci_methods,
215 sizeof(struct bt_softc),
216 };
217
218 static devclass_t bt_devclass;
219
220 DRIVER_MODULE(bt, pci, bt_pci_driver, bt_devclass, 0, 0);
221 MODULE_DEPEND(bt, pci, 1, 1, 1);
Cache object: d5466c06ef9776a7c9c86c032d69523a
|