Deleted Added
full compact
bt_pci.c (119690) bt_pci.c (127135)
1/*-
2 * Product specific probe and attach routines for:
3 * Buslogic BT946, BT948, BT956, BT958 SCSI controllers
4 *
5 * Copyright (c) 1995, 1997, 1998 Justin T. Gibbs
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Product specific probe and attach routines for:
3 * Buslogic BT946, BT948, BT956, BT958 SCSI controllers
4 *
5 * Copyright (c) 1995, 1997, 1998 Justin T. Gibbs
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/buslogic/bt_pci.c 119690 2003-09-02 17:30:40Z jhb $");
31__FBSDID("$FreeBSD: head/sys/dev/buslogic/bt_pci.c 127135 2004-03-17 17:50:55Z njl $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/mutex.h>
38#include <sys/bus.h>
39
40#include <dev/pci/pcireg.h>
41#include <dev/pci/pcivar.h>
42
43#include <machine/bus_memio.h>
44#include <machine/bus_pio.h>
45#include <machine/bus.h>
46#include <machine/resource.h>
47#include <sys/rman.h>
48
49#include <dev/buslogic/btreg.h>
50
51#define BT_PCI_IOADDR PCIR_BAR(0)
52#define BT_PCI_MEMADDR PCIR_BAR(1)
53
54#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040104Bul
55#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140104Bul
56#define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130104Bul
57
58static int
59bt_pci_alloc_resources(device_t dev)
60{
61 int command, type = 0, rid, zero;
62 struct resource *regs = 0;
63 struct resource *irq = 0;
64
65 command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
66#if 0
67 /* XXX Memory Mapped I/O seems to cause problems */
68 if (command & PCIM_CMD_MEMEN) {
69 type = SYS_RES_MEMORY;
70 rid = BT_PCI_MEMADDR;
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/mutex.h>
38#include <sys/bus.h>
39
40#include <dev/pci/pcireg.h>
41#include <dev/pci/pcivar.h>
42
43#include <machine/bus_memio.h>
44#include <machine/bus_pio.h>
45#include <machine/bus.h>
46#include <machine/resource.h>
47#include <sys/rman.h>
48
49#include <dev/buslogic/btreg.h>
50
51#define BT_PCI_IOADDR PCIR_BAR(0)
52#define BT_PCI_MEMADDR PCIR_BAR(1)
53
54#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040104Bul
55#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140104Bul
56#define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130104Bul
57
58static int
59bt_pci_alloc_resources(device_t dev)
60{
61 int command, type = 0, rid, zero;
62 struct resource *regs = 0;
63 struct resource *irq = 0;
64
65 command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
66#if 0
67 /* XXX Memory Mapped I/O seems to cause problems */
68 if (command & PCIM_CMD_MEMEN) {
69 type = SYS_RES_MEMORY;
70 rid = BT_PCI_MEMADDR;
71 regs = bus_alloc_resource(dev, type, &rid,
72 0, ~0, 1, RF_ACTIVE);
71 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
73 }
74#else
75 if (!regs && (command & PCIM_CMD_PORTEN)) {
76 type = SYS_RES_IOPORT;
77 rid = BT_PCI_IOADDR;
72 }
73#else
74 if (!regs && (command & PCIM_CMD_PORTEN)) {
75 type = SYS_RES_IOPORT;
76 rid = BT_PCI_IOADDR;
78 regs = bus_alloc_resource(dev, type, &rid,
79 0, ~0, 1, RF_ACTIVE);
77 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
80 }
81#endif
82 if (!regs)
83 return (ENOMEM);
84
85 zero = 0;
78 }
79#endif
80 if (!regs)
81 return (ENOMEM);
82
83 zero = 0;
86 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &zero,
87 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
84 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
85 RF_ACTIVE | RF_SHAREABLE);
88 if (!irq) {
89 bus_release_resource(dev, type, rid, regs);
90 return (ENOMEM);
91 }
92
93 bt_init_softc(dev, regs, irq, 0);
94
95 return (0);
96}
97
98static void
99bt_pci_release_resources(device_t dev)
100{
101 struct bt_softc *bt = device_get_softc(dev);
102
103 if (bt->port)
104 /* XXX can't cope with memory registers anyway */
105 bus_release_resource(dev, SYS_RES_IOPORT,
106 BT_PCI_IOADDR, bt->port);
107 if (bt->irq)
108 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
109 bt_free_softc(dev);
110}
111
112static int
113bt_pci_probe(device_t dev)
114{
115 switch (pci_get_devid(dev)) {
116 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER:
117 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC:
118 {
119 struct bt_softc *bt = device_get_softc(dev);
120 pci_info_data_t pci_info;
121 int error;
122
123 error = bt_pci_alloc_resources(dev);
124 if (error)
125 return (error);
126
127 /*
128 * Determine if an ISA compatible I/O port has been
129 * enabled. If so, record the port so it will not
130 * be probed by our ISA probe. If the PCI I/O port
131 * was not set to the compatibility port, disable it.
132 */
133 error = bt_cmd(bt, BOP_INQUIRE_PCI_INFO,
134 /*param*/NULL, /*paramlen*/0,
135 (u_int8_t*)&pci_info, sizeof(pci_info),
136 DEFAULT_CMD_TIMEOUT);
137 if (error == 0
138 && pci_info.io_port < BIO_DISABLED) {
139 bt_mark_probed_bio(pci_info.io_port);
140 if (rman_get_start(bt->port) !=
141 bt_iop_from_bio(pci_info.io_port)) {
142 u_int8_t new_addr;
143
144 new_addr = BIO_DISABLED;
145 bt_cmd(bt, BOP_MODIFY_IO_ADDR,
146 /*param*/&new_addr,
147 /*paramlen*/1, /*reply_buf*/NULL,
148 /*reply_len*/0,
149 DEFAULT_CMD_TIMEOUT);
150 }
151 }
152 bt_pci_release_resources(dev);
153 device_set_desc(dev, "Buslogic Multi-Master SCSI Host Adapter");
154 return (0);
155 }
156 default:
157 break;
158 }
159
160 return (ENXIO);
161}
162
163static int
164bt_pci_attach(device_t dev)
165{
166 struct bt_softc *bt = device_get_softc(dev);
167 int opri;
168 int error;
169
170 /* Initialize softc */
171 error = bt_pci_alloc_resources(dev);
172 if (error) {
173 device_printf(dev, "can't allocate resources in bt_pci_attach\n");
174 return error;
175 }
176
177 /* Allocate a dmatag for our CCB DMA maps */
178 /* XXX Should be a child of the PCI bus dma tag */
179 if (bus_dma_tag_create( /* parent */ NULL,
180 /* alignemnt */ 1,
181 /* boundary */ 0,
182 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
183 /* highaddr */ BUS_SPACE_MAXADDR,
184 /* filter */ NULL,
185 /* filterarg */ NULL,
186 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
187 /* nsegments */ ~0,
188 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
189 /* flags */ 0,
190 /* lockfunc */ busdma_lock_mutex,
191 /* lockarg */ &Giant,
192 &bt->parent_dmat) != 0) {
193 bt_pci_release_resources(dev);
194 return (ENOMEM);
195 }
196
197 /*
198 * Protect ourself from spurrious interrupts during
199 * intialization and attach. We should really rely
200 * on interrupts during attach, but we don't have
201 * access to our interrupts during ISA probes, so until
202 * that changes, we mask our interrupts during attach
203 * too.
204 */
205 opri = splcam();
206
207 if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
208 bt_pci_release_resources(dev);
209 splx(opri);
210 return (ENXIO);
211 }
212
213 error = bt_attach(dev);
214 splx(opri);
215
216 if (error) {
217 bt_pci_release_resources(dev);
218 return (error);
219 }
220
221 return (0);
222}
223
224static device_method_t bt_pci_methods[] = {
225 /* Device interface */
226 DEVMETHOD(device_probe, bt_pci_probe),
227 DEVMETHOD(device_attach, bt_pci_attach),
228
229 { 0, 0 }
230};
231
232static driver_t bt_pci_driver = {
233 "bt",
234 bt_pci_methods,
235 sizeof(struct bt_softc),
236};
237
238static devclass_t bt_devclass;
239
240DRIVER_MODULE(bt, pci, bt_pci_driver, bt_devclass, 0, 0);
86 if (!irq) {
87 bus_release_resource(dev, type, rid, regs);
88 return (ENOMEM);
89 }
90
91 bt_init_softc(dev, regs, irq, 0);
92
93 return (0);
94}
95
96static void
97bt_pci_release_resources(device_t dev)
98{
99 struct bt_softc *bt = device_get_softc(dev);
100
101 if (bt->port)
102 /* XXX can't cope with memory registers anyway */
103 bus_release_resource(dev, SYS_RES_IOPORT,
104 BT_PCI_IOADDR, bt->port);
105 if (bt->irq)
106 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
107 bt_free_softc(dev);
108}
109
110static int
111bt_pci_probe(device_t dev)
112{
113 switch (pci_get_devid(dev)) {
114 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER:
115 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC:
116 {
117 struct bt_softc *bt = device_get_softc(dev);
118 pci_info_data_t pci_info;
119 int error;
120
121 error = bt_pci_alloc_resources(dev);
122 if (error)
123 return (error);
124
125 /*
126 * Determine if an ISA compatible I/O port has been
127 * enabled. If so, record the port so it will not
128 * be probed by our ISA probe. If the PCI I/O port
129 * was not set to the compatibility port, disable it.
130 */
131 error = bt_cmd(bt, BOP_INQUIRE_PCI_INFO,
132 /*param*/NULL, /*paramlen*/0,
133 (u_int8_t*)&pci_info, sizeof(pci_info),
134 DEFAULT_CMD_TIMEOUT);
135 if (error == 0
136 && pci_info.io_port < BIO_DISABLED) {
137 bt_mark_probed_bio(pci_info.io_port);
138 if (rman_get_start(bt->port) !=
139 bt_iop_from_bio(pci_info.io_port)) {
140 u_int8_t new_addr;
141
142 new_addr = BIO_DISABLED;
143 bt_cmd(bt, BOP_MODIFY_IO_ADDR,
144 /*param*/&new_addr,
145 /*paramlen*/1, /*reply_buf*/NULL,
146 /*reply_len*/0,
147 DEFAULT_CMD_TIMEOUT);
148 }
149 }
150 bt_pci_release_resources(dev);
151 device_set_desc(dev, "Buslogic Multi-Master SCSI Host Adapter");
152 return (0);
153 }
154 default:
155 break;
156 }
157
158 return (ENXIO);
159}
160
161static int
162bt_pci_attach(device_t dev)
163{
164 struct bt_softc *bt = device_get_softc(dev);
165 int opri;
166 int error;
167
168 /* Initialize softc */
169 error = bt_pci_alloc_resources(dev);
170 if (error) {
171 device_printf(dev, "can't allocate resources in bt_pci_attach\n");
172 return error;
173 }
174
175 /* Allocate a dmatag for our CCB DMA maps */
176 /* XXX Should be a child of the PCI bus dma tag */
177 if (bus_dma_tag_create( /* parent */ NULL,
178 /* alignemnt */ 1,
179 /* boundary */ 0,
180 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
181 /* highaddr */ BUS_SPACE_MAXADDR,
182 /* filter */ NULL,
183 /* filterarg */ NULL,
184 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
185 /* nsegments */ ~0,
186 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
187 /* flags */ 0,
188 /* lockfunc */ busdma_lock_mutex,
189 /* lockarg */ &Giant,
190 &bt->parent_dmat) != 0) {
191 bt_pci_release_resources(dev);
192 return (ENOMEM);
193 }
194
195 /*
196 * Protect ourself from spurrious interrupts during
197 * intialization and attach. We should really rely
198 * on interrupts during attach, but we don't have
199 * access to our interrupts during ISA probes, so until
200 * that changes, we mask our interrupts during attach
201 * too.
202 */
203 opri = splcam();
204
205 if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
206 bt_pci_release_resources(dev);
207 splx(opri);
208 return (ENXIO);
209 }
210
211 error = bt_attach(dev);
212 splx(opri);
213
214 if (error) {
215 bt_pci_release_resources(dev);
216 return (error);
217 }
218
219 return (0);
220}
221
222static device_method_t bt_pci_methods[] = {
223 /* Device interface */
224 DEVMETHOD(device_probe, bt_pci_probe),
225 DEVMETHOD(device_attach, bt_pci_attach),
226
227 { 0, 0 }
228};
229
230static driver_t bt_pci_driver = {
231 "bt",
232 bt_pci_methods,
233 sizeof(struct bt_softc),
234};
235
236static devclass_t bt_devclass;
237
238DRIVER_MODULE(bt, pci, bt_pci_driver, bt_devclass, 0, 0);