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 $
35 * $DragonFly: src/sys/bus/firewire/fwohci_pci.c,v 1.3 2003/08/07 21:16:45 dillon Exp $
38 #define BOUNCE_BUFFER_TEST 0
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/module.h>
45 #include <sys/queue.h>
46 #include <machine/bus.h>
48 #include <sys/malloc.h>
49 #include <machine/resource.h>
51 #include <bus/pci/pcivar.h>
52 #include <bus/pci/pcireg.h>
55 #include "firewirereg.h"
58 #include "fwohcireg.h"
59 #include "fwohcivar.h"
61 static int fwohci_pci_attach(device_t self);
62 static int fwohci_pci_detach(device_t self);
68 fwohci_pci_probe( device_t dev )
73 id = pci_get_devid(dev);
74 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD861)) {
75 device_set_desc(dev, "NEC uPD72861");
78 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD871)) {
79 device_set_desc(dev, "NEC uPD72871/2");
82 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72870)) {
83 device_set_desc(dev, "NEC uPD72870");
86 if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72874)) {
87 device_set_desc(dev, "NEC uPD72874");
90 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB22)) {
91 device_set_desc(dev, "Texas Instruments TSB12LV22");
94 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB23)) {
95 device_set_desc(dev, "Texas Instruments TSB12LV23");
98 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB26)) {
99 device_set_desc(dev, "Texas Instruments TSB12LV26");
102 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43)) {
103 device_set_desc(dev, "Texas Instruments TSB43AA22");
106 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43A)) {
107 device_set_desc(dev, "Texas Instruments TSB43AB22/A");
110 if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43AB23)) {
111 device_set_desc(dev, "Texas Instruments TSB43AB23");
114 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4450)) {
115 device_set_desc(dev, "Texas Instruments PCI4450");
118 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4410A)) {
119 device_set_desc(dev, "Texas Instruments PCI4410A");
122 if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4451)) {
123 device_set_desc(dev, "Texas Instruments PCI4451");
126 if (id == (FW_VENDORID_SONY | FW_DEVICE_CX3022)) {
127 device_set_desc(dev, "Sony CX3022");
130 if (id == (FW_VENDORID_VIA | FW_DEVICE_VT6306)) {
131 device_set_desc(dev, "VIA VT6306");
134 if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C551)) {
135 device_set_desc(dev, "Ricoh R5C551");
138 if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C552)) {
139 device_set_desc(dev, "Ricoh R5C552");
142 if (id == (FW_VENDORID_APPLE | FW_DEVICE_PANGEA)) {
143 device_set_desc(dev, "Apple Pangea");
146 if (id == (FW_VENDORID_APPLE | FW_DEVICE_UNINORTH)) {
147 device_set_desc(dev, "Apple UniNorth");
150 if (id == (FW_VENDORID_LUCENT | FW_DEVICE_FW322)) {
151 device_set_desc(dev, "Lucent FW322/323");
155 if (pci_get_class(dev) == PCIC_SERIALBUS
156 && pci_get_subclass(dev) == PCIS_SERIALBUS_FW
157 && pci_get_progif(dev) == PCI_INTERFACE_OHCI) {
158 device_printf(dev, "vendor=%x, dev=%x\n", pci_get_vendor(dev),
159 pci_get_device(dev));
160 device_set_desc(dev, "1394 Open Host Controller Interface");
167 #if __FreeBSD_version < 500000
169 fwohci_dummy_intr(void *arg)
176 fwohci_pci_init(device_t self)
178 int olatency, latency, ocache_line, cache_line;
181 cmd = pci_read_config(self, PCIR_COMMAND, 2);
182 cmd |= PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN |
183 PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN;
185 cmd &= ~PCIM_CMD_MWRICEN;
187 pci_write_config(self, PCIR_COMMAND, cmd, 2);
189 latency = olatency = pci_read_config(self, PCIR_LATTIMER, 1);
190 #define DEF_LATENCY 0x20
191 if (olatency < DEF_LATENCY) {
192 latency = DEF_LATENCY;
193 pci_write_config(self, PCIR_LATTIMER, latency, 1);
196 cache_line = ocache_line = pci_read_config(self, PCIR_CACHELNSZ, 1);
197 #define DEF_CACHE_LINE 8
198 if (ocache_line < DEF_CACHE_LINE) {
199 cache_line = DEF_CACHE_LINE;
200 pci_write_config(self, PCIR_CACHELNSZ, cache_line, 1);
203 if (firewire_debug) {
204 device_printf(self, "latency timer %d -> %d.\n",
206 device_printf(self, "cache size %d -> %d.\n",
207 ocache_line, cache_line);
214 fwohci_pci_attach(device_t self)
216 fwohci_softc_t *sc = device_get_softc(self);
219 #if __FreeBSD_version < 500000
221 /* For the moment, put in a message stating what is wrong */
222 intr = pci_read_config(self, PCIR_INTLINE, 1);
223 if (intr == 0 || intr == 255) {
224 device_printf(self, "Invalid irq %d\n", intr);
226 device_printf(self, "Please switch PNP-OS to 'No' in BIOS\n");
232 firewire_debug = bootverbose;
234 fwohci_pci_init(self);
237 sc->bsr = bus_alloc_resource(self, SYS_RES_MEMORY, &rid,
238 0, ~0, 1, RF_ACTIVE);
240 device_printf(self, "Could not map memory\n");
244 sc->bst = rman_get_bustag(sc->bsr);
245 sc->bsh = rman_get_bushandle(sc->bsr);
248 sc->irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid, 0, ~0, 1,
249 RF_SHAREABLE | RF_ACTIVE);
250 if (sc->irq_res == NULL) {
251 device_printf(self, "Could not allocate irq\n");
252 fwohci_pci_detach(self);
256 sc->fc.bdev = device_add_child(self, "firewire", -1);
258 device_printf(self, "Could not add firewire device\n");
259 fwohci_pci_detach(self);
262 device_set_ivars(sc->fc.bdev, sc);
264 err = bus_setup_intr(self, sc->irq_res,
266 INTR_TYPE_NET | INTR_MPSAFE,
270 (driver_intr_t *) fwohci_intr, sc, &sc->ih);
271 #if __FreeBSD_version < 500000
272 /* XXX splcam() should mask this irq for sbp.c*/
273 err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_CAM,
274 (driver_intr_t *) fwohci_dummy_intr, sc, &sc->ih_cam);
277 device_printf(self, "Could not setup irq, %d\n", err);
278 fwohci_pci_detach(self);
282 err = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
284 #if BOUNCE_BUFFER_TEST
285 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
287 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
289 /*highaddr*/BUS_SPACE_MAXADDR,
290 /*filter*/NULL, /*filterarg*/NULL,
294 /*flags*/BUS_DMA_ALLOCNOW,
297 printf("fwohci_pci_attach: Could not allocate DMA tag "
298 "- error %d\n", err);
302 err = fwohci_init(sc, self);
305 err = device_probe_and_attach(sc->fc.bdev);
308 device_printf(self, "FireWire init failed\n");
309 fwohci_pci_detach(self);
314 * Clear the bus reset event flag to start transactions even when
315 * interrupt is disabled during the boot process.
318 fwohci_intr((void *)sc);
325 fwohci_pci_detach(device_t self)
327 fwohci_softc_t *sc = device_get_softc(self);
333 fwohci_stop(sc, self);
334 bus_generic_detach(self);
336 /* disable interrupts that might have been switched on */
337 if (sc->bst && sc->bsh)
338 bus_space_write_4(sc->bst, sc->bsh,
339 FWOHCI_INTMASKCLR, OHCI_INT_EN);
342 int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
344 /* XXX or should we panic? */
345 device_printf(self, "Could not tear down irq, %d\n",
347 #if __FreeBSD_version < 500000
348 err = bus_teardown_intr(self, sc->irq_res, sc->ih_cam);
354 device_delete_child(self, sc->fc.bdev);
359 bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
364 bus_release_resource(self, SYS_RES_MEMORY,PCI_CBMEM,sc->bsr);
370 fwohci_detach(sc, self);
377 fwohci_pci_suspend(device_t dev)
381 device_printf(dev, "fwohci_pci_suspend\n");
382 err = bus_generic_suspend(dev);
385 /* fwohci_stop(dev); */
390 fwohci_pci_resume(device_t dev)
392 fwohci_softc_t *sc = device_get_softc(dev);
394 device_printf(dev, "fwohci_pci_resume: power_state = 0x%08x\n",
395 pci_get_powerstate(dev));
396 fwohci_pci_init(dev);
397 fwohci_resume(sc, dev);
402 fwohci_pci_shutdown(device_t dev)
404 fwohci_softc_t *sc = device_get_softc(dev);
406 bus_generic_shutdown(dev);
407 fwohci_stop(sc, dev);
411 static device_method_t fwohci_methods[] = {
412 /* Device interface */
413 DEVMETHOD(device_probe, fwohci_pci_probe),
414 DEVMETHOD(device_attach, fwohci_pci_attach),
415 DEVMETHOD(device_detach, fwohci_pci_detach),
416 DEVMETHOD(device_suspend, fwohci_pci_suspend),
417 DEVMETHOD(device_resume, fwohci_pci_resume),
418 DEVMETHOD(device_shutdown, fwohci_pci_shutdown),
421 DEVMETHOD(bus_print_child, bus_generic_print_child),
426 static driver_t fwohci_driver = {
429 sizeof(fwohci_softc_t),
432 static devclass_t fwohci_devclass;
434 DRIVER_MODULE(fwohci, pci, fwohci_driver, fwohci_devclass, 0, 0);
435 DRIVER_MODULE(fwohci, cardbus, fwohci_driver, fwohci_devclass, 0, 0);