2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the acknowledgement as bellow:
17 * This product includes software developed by K. Kobayashi and H. SHimokawa
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * $FreeBSD: src/sys/dev/firewire/fwohci_pci.c,v 1.3.2.11 2003/04/28 03:29:18 simokawa Exp $
37 #define BOUNCE_BUFFER_TEST 0
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/module.h>
44 #include <sys/queue.h>
45 #include <machine/bus.h>
47 #include <sys/malloc.h>
48 #include <machine/resource.h>
50 #include <pci/pcivar.h>
51 #include <pci/pcireg.h>
53 #include <dev/firewire/firewire.h>
54 #include <dev/firewire/firewirereg.h>
56 #include <dev/firewire/fwdma.h>
57 #include <dev/firewire/fwohcireg.h>
58 #include <dev/firewire/fwohcivar.h>
60 static int fwohci_pci_attach(device_t self);
61 static int fwohci_pci_detach(device_t self);
67 fwohci_pci_probe( device_t dev )
72 id = pci_get_devid(dev);
73 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD861)) {
74 device_set_desc(dev, "NEC uPD72861");
77 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD871)) {
78 device_set_desc(dev, "NEC uPD72871/2");
81 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72870)) {
82 device_set_desc(dev, "NEC uPD72870");
85 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72874)) {
86 device_set_desc(dev, "NEC uPD72874");
89 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB22)) {
90 device_set_desc(dev, "Texas Instruments TSB12LV22");
93 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB23)) {
94 device_set_desc(dev, "Texas Instruments TSB12LV23");
97 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB26)) {
98 device_set_desc(dev, "Texas Instruments TSB12LV26");
101 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43)) {
102 device_set_desc(dev, "Texas Instruments TSB43AA22");
105 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43A)) {
106 device_set_desc(dev, "Texas Instruments TSB43AB22/A");
109 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43AB23)) {
110 device_set_desc(dev, "Texas Instruments TSB43AB23");
113 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4450)) {
114 device_set_desc(dev, "Texas Instruments PCI4450");
117 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4410A)) {
118 device_set_desc(dev, "Texas Instruments PCI4410A");
121 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4451)) {
122 device_set_desc(dev, "Texas Instruments PCI4451");
125 if (id == (FW_VENDORID_SONY | FW_DEVICE_CX3022)) {
126 device_set_desc(dev, "Sony CX3022");
129 if (id == (FW_VENDORID_VIA | FW_DEVICE_VT6306)) {
130 device_set_desc(dev, "VIA VT6306");
133 if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C551)) {
134 device_set_desc(dev, "Ricoh R5C551");
137 if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C552)) {
138 device_set_desc(dev, "Ricoh R5C552");
141 if (id == (FW_VENDORID_APPLE | FW_DEVICE_PANGEA)) {
142 device_set_desc(dev, "Apple Pangea");
145 if (id == (FW_VENDORID_APPLE | FW_DEVICE_UNINORTH)) {
146 device_set_desc(dev, "Apple UniNorth");
149 if (id == (FW_VENDORID_LUCENT | FW_DEVICE_FW322)) {
150 device_set_desc(dev, "Lucent FW322/323");
154 if (pci_get_class(dev) == PCIC_SERIALBUS
155 && pci_get_subclass(dev) == PCIS_SERIALBUS_FW
156 && pci_get_progif(dev) == PCI_INTERFACE_OHCI) {
157 device_printf(dev, "vendor=%x, dev=%x\n", pci_get_vendor(dev),
158 pci_get_device(dev));
159 device_set_desc(dev, "1394 Open Host Controller Interface");
166 #if __FreeBSD_version < 500000
168 fwohci_dummy_intr(void *arg)
175 fwohci_pci_init(device_t self)
177 int olatency, latency, ocache_line, cache_line;
180 cmd = pci_read_config(self, PCIR_COMMAND, 2);
181 cmd |= PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN |
182 PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN;
184 cmd &= ~PCIM_CMD_MWRICEN;
186 pci_write_config(self, PCIR_COMMAND, cmd, 2);
188 latency = olatency = pci_read_config(self, PCIR_LATTIMER, 1);
189 #define DEF_LATENCY 0x20
190 if (olatency < DEF_LATENCY) {
191 latency = DEF_LATENCY;
192 pci_write_config(self, PCIR_LATTIMER, latency, 1);
195 cache_line = ocache_line = pci_read_config(self, PCIR_CACHELNSZ, 1);
196 #define DEF_CACHE_LINE 8
197 if (ocache_line < DEF_CACHE_LINE) {
198 cache_line = DEF_CACHE_LINE;
199 pci_write_config(self, PCIR_CACHELNSZ, cache_line, 1);
202 if (firewire_debug) {
203 device_printf(self, "latency timer %d -> %d.\n",
205 device_printf(self, "cache size %d -> %d.\n",
206 ocache_line, cache_line);
213 fwohci_pci_attach(device_t self)
215 fwohci_softc_t *sc = device_get_softc(self);
218 #if __FreeBSD_version < 500000
220 /* For the moment, put in a message stating what is wrong */
221 intr = pci_read_config(self, PCIR_INTLINE, 1);
222 if (intr == 0 || intr == 255) {
223 device_printf(self, "Invalid irq %d\n", intr);
225 device_printf(self, "Please switch PNP-OS to 'No' in BIOS\n");
231 firewire_debug = bootverbose;
233 fwohci_pci_init(self);
236 sc->bsr = bus_alloc_resource(self, SYS_RES_MEMORY, &rid,
237 0, ~0, 1, RF_ACTIVE);
239 device_printf(self, "Could not map memory\n");
243 sc->bst = rman_get_bustag(sc->bsr);
244 sc->bsh = rman_get_bushandle(sc->bsr);
247 sc->irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid, 0, ~0, 1,
248 RF_SHAREABLE | RF_ACTIVE);
249 if (sc->irq_res == NULL) {
250 device_printf(self, "Could not allocate irq\n");
251 fwohci_pci_detach(self);
255 sc->fc.bdev = device_add_child(self, "firewire", -1);
257 device_printf(self, "Could not add firewire device\n");
258 fwohci_pci_detach(self);
261 device_set_ivars(sc->fc.bdev, sc);
263 err = bus_setup_intr(self, sc->irq_res,
265 INTR_TYPE_NET | INTR_MPSAFE,
269 (driver_intr_t *) fwohci_intr, sc, &sc->ih);
270 #if __FreeBSD_version < 500000
271 /* XXX splcam() should mask this irq for sbp.c*/
272 err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_CAM,
273 (driver_intr_t *) fwohci_dummy_intr, sc, &sc->ih_cam);
276 device_printf(self, "Could not setup irq, %d\n", err);
277 fwohci_pci_detach(self);
281 err = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
283 #if BOUNCE_BUFFER_TEST
284 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
286 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
288 /*highaddr*/BUS_SPACE_MAXADDR,
289 /*filter*/NULL, /*filterarg*/NULL,
293 /*flags*/BUS_DMA_ALLOCNOW,
296 printf("fwohci_pci_attach: Could not allocate DMA tag "
297 "- error %d\n", err);
301 err = fwohci_init(sc, self);
304 err = device_probe_and_attach(sc->fc.bdev);
307 device_printf(self, "FireWire init failed\n");
308 fwohci_pci_detach(self);
313 * Clear the bus reset event flag to start transactions even when
314 * interrupt is disabled during the boot process.
317 fwohci_intr((void *)sc);
324 fwohci_pci_detach(device_t self)
326 fwohci_softc_t *sc = device_get_softc(self);
332 fwohci_stop(sc, self);
333 bus_generic_detach(self);
335 /* disable interrupts that might have been switched on */
336 if (sc->bst && sc->bsh)
337 bus_space_write_4(sc->bst, sc->bsh,
338 FWOHCI_INTMASKCLR, OHCI_INT_EN);
341 int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
343 /* XXX or should we panic? */
344 device_printf(self, "Could not tear down irq, %d\n",
346 #if __FreeBSD_version < 500000
347 err = bus_teardown_intr(self, sc->irq_res, sc->ih_cam);
353 device_delete_child(self, sc->fc.bdev);
358 bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
363 bus_release_resource(self, SYS_RES_MEMORY,PCI_CBMEM,sc->bsr);
369 fwohci_detach(sc, self);
376 fwohci_pci_suspend(device_t dev)
380 device_printf(dev, "fwohci_pci_suspend\n");
381 err = bus_generic_suspend(dev);
384 /* fwohci_stop(dev); */
389 fwohci_pci_resume(device_t dev)
391 fwohci_softc_t *sc = device_get_softc(dev);
393 device_printf(dev, "fwohci_pci_resume: power_state = 0x%08x\n",
394 pci_get_powerstate(dev));
395 fwohci_pci_init(dev);
396 fwohci_resume(sc, dev);
401 fwohci_pci_shutdown(device_t dev)
403 fwohci_softc_t *sc = device_get_softc(dev);
405 bus_generic_shutdown(dev);
406 fwohci_stop(sc, dev);
410 static device_method_t fwohci_methods[] = {
411 /* Device interface */
412 DEVMETHOD(device_probe, fwohci_pci_probe),
413 DEVMETHOD(device_attach, fwohci_pci_attach),
414 DEVMETHOD(device_detach, fwohci_pci_detach),
415 DEVMETHOD(device_suspend, fwohci_pci_suspend),
416 DEVMETHOD(device_resume, fwohci_pci_resume),
417 DEVMETHOD(device_shutdown, fwohci_pci_shutdown),
420 DEVMETHOD(bus_print_child, bus_generic_print_child),
425 static driver_t fwohci_driver = {
428 sizeof(fwohci_softc_t),
431 static devclass_t fwohci_devclass;
433 DRIVER_MODULE(fwohci, pci, fwohci_driver, fwohci_devclass, 0, 0);
434 DRIVER_MODULE(fwohci, cardbus, fwohci_driver, fwohci_devclass, 0, 0);