2002-09-13 12:31:56 +00:00
|
|
|
/*
|
2003-04-17 03:38:03 +00:00
|
|
|
* Copyright (c) 2003 Hidetoshi Shimokawa
|
2002-09-13 12:31:56 +00:00
|
|
|
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the acknowledgement as bellow:
|
|
|
|
*
|
|
|
|
* This product includes software developed by K. Kobayashi and H. SHimokawa
|
|
|
|
*
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#define BOUNCE_BUFFER_TEST 0
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
2003-02-01 15:04:33 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 501102
|
2003-07-01 15:52:06 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2003-07-18 14:31:16 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2003-06-30 06:33:18 +00:00
|
|
|
#include <machine/clock.h> /* for DELAY() */
|
|
|
|
#endif
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#ifdef __DragonFly__
|
|
|
|
#include <bus/pci/pcivar.h>
|
|
|
|
#include <bus/pci/pcireg.h>
|
|
|
|
|
|
|
|
#include "firewire.h"
|
|
|
|
#include "firewirereg.h"
|
|
|
|
|
|
|
|
#include "fwdma.h"
|
|
|
|
#include "fwohcireg.h"
|
|
|
|
#include "fwohcivar.h"
|
|
|
|
#else
|
2003-08-22 07:33:20 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#else
|
2003-08-22 05:54:52 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
2003-08-22 07:33:20 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <dev/firewire/fwdma.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <dev/firewire/fwohcireg.h>
|
|
|
|
#include <dev/firewire/fwohcivar.h>
|
2004-03-26 23:17:10 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
static int fwohci_pci_attach(device_t self);
|
|
|
|
static int fwohci_pci_detach(device_t self);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The probe routine.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fwohci_pci_probe( device_t dev )
|
|
|
|
{
|
|
|
|
#if 1
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t id;
|
2002-12-31 13:43:44 +00:00
|
|
|
|
2003-02-18 10:01:44 +00:00
|
|
|
id = pci_get_devid(dev);
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD861)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "NEC uPD72861");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-18 09:46:52 +00:00
|
|
|
if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD871)) {
|
|
|
|
device_set_desc(dev, "NEC uPD72871/2");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-24 07:29:52 +00:00
|
|
|
if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72870)) {
|
|
|
|
device_set_desc(dev, "NEC uPD72870");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-30 14:30:19 +00:00
|
|
|
if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72873)) {
|
|
|
|
device_set_desc(dev, "NEC uPD72873");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-24 07:29:52 +00:00
|
|
|
if (id == (FW_VENDORID_NEC | FW_DEVICE_UPD72874)) {
|
|
|
|
device_set_desc(dev, "NEC uPD72874");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB22)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "Texas Instruments TSB12LV22");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB23)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "Texas Instruments TSB12LV23");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB26)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "Texas Instruments TSB12LV26");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "Texas Instruments TSB43AA22");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43A)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments TSB43AB22/A");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-24 07:29:52 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB43AB23)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments TSB43AB23");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-04 04:26:14 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TITSB82AA2)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments TSB82AA2");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4450)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments PCI4450");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4410A)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments PCI4410A");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-24 07:29:52 +00:00
|
|
|
if (id == (FW_VENDORID_TI | FW_DEVICE_TIPCI4451)) {
|
|
|
|
device_set_desc(dev, "Texas Instruments PCI4451");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_SONY | FW_DEVICE_CX3022)) {
|
2003-04-17 03:38:03 +00:00
|
|
|
device_set_desc(dev, "Sony CX3022");
|
2002-09-13 12:31:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_VIA | FW_DEVICE_VT6306)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "VIA VT6306");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-24 07:29:52 +00:00
|
|
|
if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C551)) {
|
|
|
|
device_set_desc(dev, "Ricoh R5C551");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_RICOH | FW_DEVICE_R5C552)) {
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "Ricoh R5C552");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_APPLE | FW_DEVICE_PANGEA)) {
|
2002-09-17 12:50:43 +00:00
|
|
|
device_set_desc(dev, "Apple Pangea");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_APPLE | FW_DEVICE_UNINORTH)) {
|
2002-09-17 12:50:43 +00:00
|
|
|
device_set_desc(dev, "Apple UniNorth");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-31 13:43:44 +00:00
|
|
|
if (id == (FW_VENDORID_LUCENT | FW_DEVICE_FW322)) {
|
2002-09-17 12:50:43 +00:00
|
|
|
device_set_desc(dev, "Lucent FW322/323");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
|
|
|
if (pci_get_class(dev) == PCIC_SERIALBUS
|
|
|
|
&& pci_get_subclass(dev) == PCIS_SERIALBUS_FW
|
|
|
|
&& pci_get_progif(dev) == PCI_INTERFACE_OHCI) {
|
2002-12-31 13:43:44 +00:00
|
|
|
device_printf(dev, "vendor=%x, dev=%x\n", pci_get_vendor(dev),
|
2002-09-17 12:50:43 +00:00
|
|
|
pci_get_device(dev));
|
2002-09-13 12:31:56 +00:00
|
|
|
device_set_desc(dev, "1394 Open Host Controller Interface");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2002-09-13 12:31:56 +00:00
|
|
|
static void
|
|
|
|
fwohci_dummy_intr(void *arg)
|
|
|
|
{
|
|
|
|
/* XXX do nothing */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2003-01-04 06:40:57 +00:00
|
|
|
fwohci_pci_init(device_t self)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-04-17 03:38:03 +00:00
|
|
|
int olatency, latency, ocache_line, cache_line;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t cmd;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
cmd = pci_read_config(self, PCIR_COMMAND, 2);
|
2003-03-24 03:47:36 +00:00
|
|
|
cmd |= PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN |
|
|
|
|
PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN;
|
|
|
|
#if 1
|
|
|
|
cmd &= ~PCIM_CMD_MWRICEN;
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
pci_write_config(self, PCIR_COMMAND, cmd, 2);
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
latency = olatency = pci_read_config(self, PCIR_LATTIMER, 1);
|
2003-03-24 03:47:36 +00:00
|
|
|
#define DEF_LATENCY 0x20
|
2003-04-17 03:38:03 +00:00
|
|
|
if (olatency < DEF_LATENCY) {
|
2002-09-13 12:31:56 +00:00
|
|
|
latency = DEF_LATENCY;
|
2003-04-17 03:38:03 +00:00
|
|
|
pci_write_config(self, PCIR_LATTIMER, latency, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_line = ocache_line = pci_read_config(self, PCIR_CACHELNSZ, 1);
|
|
|
|
#define DEF_CACHE_LINE 8
|
|
|
|
if (ocache_line < DEF_CACHE_LINE) {
|
|
|
|
cache_line = DEF_CACHE_LINE;
|
|
|
|
pci_write_config(self, PCIR_CACHELNSZ, cache_line, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firewire_debug) {
|
|
|
|
device_printf(self, "latency timer %d -> %d.\n",
|
|
|
|
olatency, latency);
|
|
|
|
device_printf(self, "cache size %d -> %d.\n",
|
|
|
|
ocache_line, cache_line);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-04 06:40:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_pci_attach(device_t self)
|
|
|
|
{
|
|
|
|
fwohci_softc_t *sc = device_get_softc(self);
|
|
|
|
int err;
|
2004-01-30 14:28:11 +00:00
|
|
|
int rid;
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2003-01-04 06:40:57 +00:00
|
|
|
int intr;
|
|
|
|
/* For the moment, put in a message stating what is wrong */
|
|
|
|
intr = pci_read_config(self, PCIR_INTLINE, 1);
|
|
|
|
if (intr == 0 || intr == 255) {
|
|
|
|
device_printf(self, "Invalid irq %d\n", intr);
|
|
|
|
#ifdef __i386__
|
|
|
|
device_printf(self, "Please switch PNP-OS to 'No' in BIOS\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
if (bootverbose)
|
|
|
|
firewire_debug = bootverbose;
|
|
|
|
|
2003-01-04 06:40:57 +00:00
|
|
|
fwohci_pci_init(self);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
rid = PCI_CBMEM;
|
2004-03-26 23:17:10 +00:00
|
|
|
#if __FreeBSD_version >= 502109
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->bsr = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE);
|
2004-03-26 23:17:10 +00:00
|
|
|
#else
|
|
|
|
sc->bsr = bus_alloc_resource(self, SYS_RES_MEMORY, &rid,
|
|
|
|
0, ~0, 1, RF_ACTIVE);
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
if (!sc->bsr) {
|
|
|
|
device_printf(self, "Could not map memory\n");
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->bst = rman_get_bustag(sc->bsr);
|
|
|
|
sc->bsh = rman_get_bushandle(sc->bsr);
|
|
|
|
|
|
|
|
rid = 0;
|
2004-03-26 23:17:10 +00:00
|
|
|
#if __FreeBSD_version >= 502109
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
|
2002-09-13 12:31:56 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
2004-03-26 23:17:10 +00:00
|
|
|
#else
|
|
|
|
sc->irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid, 0, ~0, 1,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
if (sc->irq_res == NULL) {
|
|
|
|
device_printf(self, "Could not allocate irq\n");
|
|
|
|
fwohci_pci_detach(self);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
err = bus_setup_intr(self, sc->irq_res,
|
|
|
|
#if FWOHCI_TASKQUEUE
|
|
|
|
INTR_TYPE_NET | INTR_MPSAFE,
|
|
|
|
#else
|
|
|
|
INTR_TYPE_NET,
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
(driver_intr_t *) fwohci_intr, sc, &sc->ih);
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2002-09-13 12:31:56 +00:00
|
|
|
/* XXX splcam() should mask this irq for sbp.c*/
|
|
|
|
err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_CAM,
|
|
|
|
(driver_intr_t *) fwohci_dummy_intr, sc, &sc->ih_cam);
|
2003-10-25 15:05:59 +00:00
|
|
|
/* XXX splbio() should mask this irq for physio()/fwmem_strategy() */
|
|
|
|
err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO,
|
|
|
|
(driver_intr_t *) fwohci_dummy_intr, sc, &sc->ih_bio);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
|
|
|
if (err) {
|
|
|
|
device_printf(self, "Could not setup irq, %d\n", err);
|
|
|
|
fwohci_pci_detach(self);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
err = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
|
|
|
|
/*boundary*/0,
|
|
|
|
#if BOUNCE_BUFFER_TEST
|
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
|
|
|
|
#else
|
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
#endif
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/0x100000,
|
|
|
|
/*nsegments*/0x20,
|
|
|
|
/*maxsegsz*/0x8000,
|
|
|
|
/*flags*/BUS_DMA_ALLOCNOW,
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 501102
|
2003-07-01 15:52:06 +00:00
|
|
|
/*lockfunc*/busdma_lock_mutex,
|
2003-07-04 14:04:41 +00:00
|
|
|
/*lockarg*/&Giant,
|
|
|
|
#endif
|
|
|
|
&sc->fc.dmat);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (err != 0) {
|
|
|
|
printf("fwohci_pci_attach: Could not allocate DMA tag "
|
|
|
|
"- error %d\n", err);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
err = fwohci_init(sc, self);
|
|
|
|
|
2004-01-23 17:37:09 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(self, "fwohci_init failed with err=%d\n", err);
|
|
|
|
fwohci_pci_detach(self);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
2004-01-30 14:28:11 +00:00
|
|
|
/* probe and attach a child device(firewire) */
|
|
|
|
bus_generic_probe(self);
|
|
|
|
bus_generic_attach(self);
|
2003-02-14 15:52:32 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_pci_detach(device_t self)
|
|
|
|
{
|
|
|
|
fwohci_softc_t *sc = device_get_softc(self);
|
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
|
|
s = splfw();
|
2003-01-01 08:25:32 +00:00
|
|
|
|
2003-08-04 05:43:02 +00:00
|
|
|
if (sc->bsr)
|
|
|
|
fwohci_stop(sc, self);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
bus_generic_detach(self);
|
2003-08-04 05:43:02 +00:00
|
|
|
if (sc->fc.bdev) {
|
|
|
|
device_delete_child(self, sc->fc.bdev);
|
|
|
|
sc->fc.bdev = NULL;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
/* disable interrupts that might have been switched on */
|
|
|
|
if (sc->bst && sc->bsh)
|
|
|
|
bus_space_write_4(sc->bst, sc->bsh,
|
|
|
|
FWOHCI_INTMASKCLR, OHCI_INT_EN);
|
|
|
|
|
|
|
|
if (sc->irq_res) {
|
|
|
|
int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
|
|
|
|
if (err)
|
|
|
|
/* XXX or should we panic? */
|
|
|
|
device_printf(self, "Could not tear down irq, %d\n",
|
|
|
|
err);
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2003-10-25 15:05:59 +00:00
|
|
|
bus_teardown_intr(self, sc->irq_res, sc->ih_cam);
|
|
|
|
bus_teardown_intr(self, sc->irq_res, sc->ih_bio);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
|
|
|
sc->ih = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->irq_res) {
|
|
|
|
bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
|
|
|
|
sc->irq_res = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->bsr) {
|
|
|
|
bus_release_resource(self, SYS_RES_MEMORY,PCI_CBMEM,sc->bsr);
|
|
|
|
sc->bsr = NULL;
|
|
|
|
sc->bst = 0;
|
|
|
|
sc->bsh = 0;
|
|
|
|
}
|
2003-01-01 04:23:54 +00:00
|
|
|
|
|
|
|
fwohci_detach(sc, self);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-12 13:46:09 +00:00
|
|
|
static int
|
|
|
|
fwohci_pci_suspend(device_t dev)
|
|
|
|
{
|
2003-06-28 11:11:36 +00:00
|
|
|
fwohci_softc_t *sc = device_get_softc(dev);
|
2003-01-04 06:40:57 +00:00
|
|
|
int err;
|
2003-01-05 09:12:47 +00:00
|
|
|
|
|
|
|
device_printf(dev, "fwohci_pci_suspend\n");
|
2003-01-04 06:40:57 +00:00
|
|
|
err = bus_generic_suspend(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2003-06-28 11:11:36 +00:00
|
|
|
fwohci_stop(sc, dev);
|
2002-11-12 13:46:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_pci_resume(device_t dev)
|
|
|
|
{
|
2003-01-01 08:25:32 +00:00
|
|
|
fwohci_softc_t *sc = device_get_softc(dev);
|
|
|
|
|
2003-07-03 14:00:57 +00:00
|
|
|
#ifndef BURN_BRIDGES
|
2003-01-04 06:40:57 +00:00
|
|
|
device_printf(dev, "fwohci_pci_resume: power_state = 0x%08x\n",
|
|
|
|
pci_get_powerstate(dev));
|
2003-06-28 11:11:36 +00:00
|
|
|
pci_set_powerstate(dev, PCI_POWERSTATE_D0);
|
2003-07-03 14:00:57 +00:00
|
|
|
#endif
|
2003-01-04 06:40:57 +00:00
|
|
|
fwohci_pci_init(dev);
|
|
|
|
fwohci_resume(sc, dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwohci_pci_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
fwohci_softc_t *sc = device_get_softc(dev);
|
|
|
|
|
2003-01-31 14:11:22 +00:00
|
|
|
bus_generic_shutdown(dev);
|
|
|
|
fwohci_stop(sc, dev);
|
2002-11-12 13:46:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-30 14:28:11 +00:00
|
|
|
static device_t
|
|
|
|
fwohci_pci_add_child(device_t dev, int order, const char *name, int unit)
|
|
|
|
{
|
|
|
|
struct fwohci_softc *sc;
|
|
|
|
device_t child;
|
|
|
|
int s, err = 0;
|
|
|
|
|
|
|
|
sc = (struct fwohci_softc *)device_get_softc(dev);
|
|
|
|
child = device_add_child(dev, name, unit);
|
|
|
|
if (child == NULL)
|
|
|
|
return (child);
|
|
|
|
|
|
|
|
sc->fc.bdev = child;
|
|
|
|
device_set_ivars(child, (void *)&sc->fc);
|
|
|
|
|
|
|
|
err = device_probe_and_attach(child);
|
|
|
|
if (err) {
|
|
|
|
device_printf(dev, "probe_and_attach failed with err=%d\n",
|
|
|
|
err);
|
|
|
|
fwohci_pci_detach(dev);
|
|
|
|
device_delete_child(dev, child);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX
|
|
|
|
* Clear the bus reset event flag to start transactions even when
|
|
|
|
* interrupt is disabled during the boot process.
|
|
|
|
*/
|
|
|
|
DELAY(250); /* 2 cycles */
|
|
|
|
s = splfw();
|
|
|
|
fwohci_poll((void *)sc, 0, -1);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (child);
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
static device_method_t fwohci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fwohci_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, fwohci_pci_attach),
|
|
|
|
DEVMETHOD(device_detach, fwohci_pci_detach),
|
2002-11-12 13:46:09 +00:00
|
|
|
DEVMETHOD(device_suspend, fwohci_pci_suspend),
|
|
|
|
DEVMETHOD(device_resume, fwohci_pci_resume),
|
2003-01-04 06:40:57 +00:00
|
|
|
DEVMETHOD(device_shutdown, fwohci_pci_shutdown),
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
/* Bus interface */
|
2004-01-30 14:28:11 +00:00
|
|
|
DEVMETHOD(bus_add_child, fwohci_pci_add_child),
|
2002-09-13 12:31:56 +00:00
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t fwohci_driver = {
|
|
|
|
"fwohci",
|
|
|
|
fwohci_methods,
|
|
|
|
sizeof(fwohci_softc_t),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t fwohci_devclass;
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#ifdef FWOHCI_MODULE
|
2004-01-30 14:28:11 +00:00
|
|
|
MODULE_DEPEND(fwohci, firewire, 1, 1, 1);
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
DRIVER_MODULE(fwohci, pci, fwohci_driver, fwohci_devclass, 0, 0);
|
2003-11-28 05:28:29 +00:00
|
|
|
DRIVER_MODULE(fwohci, cardbus, fwohci_driver, fwohci_devclass, 0, 0);
|