Home | History | Annotate | Line # | Download | only in pci
fwohci_pci.c revision 1.32.10.1
      1  1.32.10.1       riz /*	$NetBSD: fwohci_pci.c,v 1.32.10.1 2010/11/21 23:34:56 riz Exp $	*/
      2        1.5     enami 
      3        1.1      matt /*-
      4        1.1      matt  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5        1.1      matt  * All rights reserved.
      6        1.1      matt  *
      7        1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1      matt  * by Matt Thomas of 3am Software Foundry.
      9        1.1      matt  *
     10        1.1      matt  * Redistribution and use in source and binary forms, with or without
     11        1.1      matt  * modification, are permitted provided that the following conditions
     12        1.1      matt  * are met:
     13        1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14        1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15        1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17        1.1      matt  *    documentation and/or other materials provided with the distribution.
     18        1.1      matt  *
     19        1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1      matt  */
     31       1.11     lukem 
     32       1.11     lukem #include <sys/cdefs.h>
     33  1.32.10.1       riz __KERNEL_RCSID(0, "$NetBSD: fwohci_pci.c,v 1.32.10.1 2010/11/21 23:34:56 riz Exp $");
     34        1.1      matt 
     35        1.1      matt #include <sys/param.h>
     36        1.2  augustss #include <sys/systm.h>
     37        1.1      matt #include <sys/socket.h>
     38        1.1      matt #include <sys/device.h>
     39       1.17      haya #include <sys/select.h>
     40        1.1      matt 
     41       1.26        ad #include <sys/bus.h>
     42       1.26        ad #include <sys/intr.h>
     43        1.1      matt 
     44        1.1      matt #include <dev/pci/pcireg.h>
     45        1.1      matt #include <dev/pci/pcivar.h>
     46  1.32.10.1       riz #include <dev/pci/pcidevs.h>
     47       1.22  kiyohara #include <dev/ieee1394/fw_port.h>
     48       1.22  kiyohara #include <dev/ieee1394/firewire.h>
     49       1.22  kiyohara #include <dev/ieee1394/firewirereg.h>
     50       1.22  kiyohara #include <dev/ieee1394/fwdma.h>
     51        1.1      matt #include <dev/ieee1394/fwohcireg.h>
     52        1.1      matt #include <dev/ieee1394/fwohcivar.h>
     53        1.1      matt 
     54        1.1      matt struct fwohci_pci_softc {
     55        1.1      matt 	struct fwohci_softc psc_sc;
     56       1.27  kiyohara 
     57        1.1      matt 	pci_chipset_tag_t psc_pc;
     58       1.27  kiyohara 	pcitag_t psc_tag;
     59       1.27  kiyohara 
     60        1.1      matt 	void *psc_ih;
     61        1.1      matt };
     62        1.1      matt 
     63       1.31  kiyohara static int fwohci_pci_match(device_t, struct cfdata *, void *);
     64       1.31  kiyohara static void fwohci_pci_attach(device_t, device_t, void *);
     65       1.28  jmcneill 
     66       1.29    dyoung static bool fwohci_pci_suspend(device_t PMF_FN_PROTO);
     67       1.29    dyoung static bool fwohci_pci_resume(device_t PMF_FN_PROTO);
     68        1.1      matt 
     69       1.31  kiyohara CFATTACH_DECL_NEW(fwohci_pci, sizeof(struct fwohci_pci_softc),
     70       1.16   thorpej     fwohci_pci_match, fwohci_pci_attach, NULL, NULL);
     71        1.1      matt 
     72        1.1      matt static int
     73       1.31  kiyohara fwohci_pci_match(device_t parent, struct cfdata *match,
     74       1.24  christos     void *aux)
     75        1.1      matt {
     76        1.7     enami 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     77        1.1      matt 
     78  1.32.10.1       riz 	/*
     79  1.32.10.1       riz 	 * XXX
     80  1.32.10.1       riz 	 * Firewire controllers used in some G3 PowerBooks hang the system
     81  1.32.10.1       riz 	 * when trying to discover devices - don't attach to those for now
     82  1.32.10.1       riz 	 * until someone with the right hardware can investigate
     83  1.32.10.1       riz 	 */
     84  1.32.10.1       riz 	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE) &&
     85  1.32.10.1       riz 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_PBG3_FW))
     86  1.32.10.1       riz 	    return 0;
     87        1.7     enami 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS &&
     88        1.7     enami 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_FIREWIRE &&
     89        1.7     enami 	    PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_OHCI)
     90        1.7     enami 		return 1;
     91       1.21     perry 
     92        1.7     enami 	return 0;
     93        1.1      matt }
     94        1.1      matt 
     95        1.1      matt static void
     96       1.31  kiyohara fwohci_pci_attach(device_t parent, device_t self, void *aux)
     97        1.1      matt {
     98        1.7     enami 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     99       1.31  kiyohara 	struct fwohci_pci_softc *psc = device_private(self);
    100        1.7     enami 	char devinfo[256];
    101        1.1      matt 	char const *intrstr;
    102        1.1      matt 	pci_intr_handle_t ih;
    103        1.1      matt 	u_int32_t csr;
    104        1.1      matt 
    105       1.18   thorpej 	aprint_naive(": IEEE 1394 Controller\n");
    106       1.18   thorpej 
    107       1.19    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    108       1.18   thorpej 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    109       1.18   thorpej 	    PCI_REVISION(pa->pa_class));
    110        1.1      matt 
    111       1.31  kiyohara 	psc->psc_sc.fc.dev = self;
    112       1.22  kiyohara 	psc->psc_sc.fc.dmat = pa->pa_dmat;
    113        1.1      matt 	psc->psc_pc = pa->pa_pc;
    114       1.27  kiyohara 	psc->psc_tag = pa->pa_tag;
    115        1.1      matt 
    116        1.7     enami 	/* Map I/O registers */
    117        1.7     enami 	if (pci_mapreg_map(pa, PCI_OHCI_MAP_REGISTER, PCI_MAPREG_TYPE_MEM, 0,
    118       1.22  kiyohara 	    &psc->psc_sc.bst, &psc->psc_sc.bsh,
    119       1.22  kiyohara 	    NULL, &psc->psc_sc.bssize)) {
    120       1.31  kiyohara 		aprint_error_dev(self, "can't map OHCI register space\n");
    121       1.28  jmcneill 		goto fail;
    122        1.7     enami 	}
    123        1.7     enami 
    124        1.7     enami 	/* Disable interrupts, so we don't get any spurious ones. */
    125       1.22  kiyohara 	OHCI_CSR_WRITE(&psc->psc_sc, FWOHCI_INTMASKCLR, OHCI_INT_EN);
    126        1.7     enami 
    127        1.7     enami 	/* Enable the device. */
    128        1.7     enami 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    129        1.7     enami 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    130        1.7     enami 	    csr | PCI_COMMAND_MASTER_ENABLE);
    131        1.8     enami 
    132        1.1      matt 	/* Map and establish the interrupt. */
    133        1.6  sommerfe 	if (pci_intr_map(pa, &ih)) {
    134       1.31  kiyohara 		aprint_error_dev(self, "couldn't map interrupt\n");
    135       1.28  jmcneill 		goto fail;
    136        1.1      matt 	}
    137        1.1      matt 	intrstr = pci_intr_string(pa->pa_pc, ih);
    138       1.27  kiyohara 	psc->psc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, fwohci_filt,
    139        1.7     enami 	    &psc->psc_sc);
    140        1.1      matt 	if (psc->psc_ih == NULL) {
    141       1.31  kiyohara 		aprint_error_dev(self, "couldn't establish interrupt");
    142        1.1      matt 		if (intrstr != NULL)
    143       1.31  kiyohara 			aprint_error(" at %s", intrstr);
    144       1.31  kiyohara 		aprint_error("\n");
    145       1.28  jmcneill 		goto fail;
    146        1.1      matt 	}
    147       1.31  kiyohara 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
    148        1.1      matt 
    149       1.28  jmcneill 	if (!pmf_device_register(self, fwohci_pci_suspend, fwohci_pci_resume))
    150       1.28  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    151       1.27  kiyohara 
    152       1.30        ad 	if (fwohci_init(&(psc->psc_sc), psc->psc_sc.fc.dev) != 0) {
    153        1.3      onoe 		pci_intr_disestablish(pa->pa_pc, psc->psc_ih);
    154       1.22  kiyohara 		bus_space_unmap(psc->psc_sc.bst, psc->psc_sc.bsh,
    155       1.22  kiyohara 		    psc->psc_sc.bssize);
    156        1.3      onoe 	}
    157       1.28  jmcneill 
    158       1.28  jmcneill 	return;
    159       1.28  jmcneill 
    160       1.28  jmcneill fail:
    161       1.28  jmcneill 	/* In the event that we fail to attach, register a null pnp handler */
    162       1.28  jmcneill 	if (!pmf_device_register(self, NULL, NULL))
    163       1.28  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    164       1.28  jmcneill 
    165       1.28  jmcneill 	return;
    166        1.1      matt }
    167       1.27  kiyohara 
    168       1.28  jmcneill static bool
    169       1.29    dyoung fwohci_pci_suspend(device_t dv PMF_FN_ARGS)
    170       1.27  kiyohara {
    171       1.28  jmcneill 	struct fwohci_pci_softc *psc = device_private(dv);
    172       1.28  jmcneill 	int s;
    173       1.27  kiyohara 
    174       1.28  jmcneill 	s = splbio();
    175       1.27  kiyohara 	fwohci_stop(&psc->psc_sc, psc->psc_sc.fc.dev);
    176       1.28  jmcneill 	splx(s);
    177       1.28  jmcneill 
    178       1.28  jmcneill 	return true;
    179       1.27  kiyohara }
    180       1.27  kiyohara 
    181       1.28  jmcneill static bool
    182       1.29    dyoung fwohci_pci_resume(device_t dv PMF_FN_ARGS)
    183       1.27  kiyohara {
    184       1.28  jmcneill 	struct fwohci_pci_softc *psc = device_private(dv);
    185       1.27  kiyohara 	int s;
    186       1.27  kiyohara 
    187       1.27  kiyohara 	s = splbio();
    188       1.28  jmcneill 	fwohci_resume(&psc->psc_sc, psc->psc_sc.fc.dev);
    189       1.27  kiyohara 	splx(s);
    190       1.28  jmcneill 
    191       1.28  jmcneill 	return true;
    192       1.27  kiyohara }
    193