Home | History | Annotate | Line # | Download | only in pci
if_ex_pci.c revision 1.37.4.1
      1  1.37.4.1      kent /*	$NetBSD: if_ex_pci.c,v 1.37.4.1 2005/04/29 11:29:06 kent Exp $	*/
      2       1.1      fvdl 
      3       1.1      fvdl /*-
      4       1.1      fvdl  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1      fvdl  * All rights reserved.
      6       1.1      fvdl  *
      7       1.1      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8       1.3   thorpej  * by Frank van der Linden; Jason R. Thorpe of the Numerical Aerospace
      9       1.3   thorpej  * Simulation Facility, NASA Ames Research Center.
     10       1.1      fvdl  *
     11       1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     12       1.1      fvdl  * modification, are permitted provided that the following conditions
     13       1.1      fvdl  * are met:
     14       1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     15       1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     16       1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     18       1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     19       1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     20       1.1      fvdl  *    must display the following acknowledgement:
     21       1.1      fvdl  *	This product includes software developed by the NetBSD
     22       1.1      fvdl  *	Foundation, Inc. and its contributors.
     23       1.1      fvdl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1      fvdl  *    contributors may be used to endorse or promote products derived
     25       1.1      fvdl  *    from this software without specific prior written permission.
     26       1.1      fvdl  *
     27       1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1      fvdl  */
     39      1.19     lukem 
     40      1.19     lukem #include <sys/cdefs.h>
     41  1.37.4.1      kent __KERNEL_RCSID(0, "$NetBSD: if_ex_pci.c,v 1.37.4.1 2005/04/29 11:29:06 kent Exp $");
     42       1.1      fvdl 
     43       1.1      fvdl #include <sys/param.h>
     44       1.1      fvdl #include <sys/systm.h>
     45  1.37.4.1      kent #include <sys/mbuf.h>
     46  1.37.4.1      kent #include <sys/socket.h>
     47       1.1      fvdl #include <sys/ioctl.h>
     48       1.1      fvdl #include <sys/errno.h>
     49       1.1      fvdl #include <sys/syslog.h>
     50       1.1      fvdl #include <sys/select.h>
     51       1.1      fvdl #include <sys/device.h>
     52       1.1      fvdl 
     53       1.1      fvdl #include <net/if.h>
     54       1.1      fvdl #include <net/if_dl.h>
     55       1.1      fvdl #include <net/if_ether.h>
     56       1.1      fvdl #include <net/if_media.h>
     57       1.1      fvdl 
     58       1.1      fvdl #include <machine/cpu.h>
     59       1.1      fvdl #include <machine/bus.h>
     60       1.1      fvdl #include <machine/intr.h>
     61       1.1      fvdl 
     62       1.1      fvdl #include <dev/mii/miivar.h>
     63       1.1      fvdl #include <dev/mii/mii.h>
     64       1.1      fvdl 
     65       1.1      fvdl #include <dev/ic/elink3var.h>
     66       1.1      fvdl #include <dev/ic/elink3reg.h>
     67       1.1      fvdl #include <dev/ic/elinkxlreg.h>
     68       1.1      fvdl #include <dev/ic/elinkxlvar.h>
     69       1.1      fvdl 
     70       1.1      fvdl #include <dev/pci/pcivar.h>
     71       1.1      fvdl #include <dev/pci/pcireg.h>
     72       1.1      fvdl #include <dev/pci/pcidevs.h>
     73       1.1      fvdl 
     74      1.14      fvdl struct ex_pci_softc {
     75      1.14      fvdl 	struct ex_softc sc_ex;
     76      1.18   kanaoka 
     77      1.18   kanaoka 	/* PCI function status space. 556,556B requests it. */
     78      1.18   kanaoka 	bus_space_tag_t sc_funct;
     79      1.18   kanaoka 	bus_space_handle_t sc_funch;
     80      1.18   kanaoka 
     81      1.21   thorpej 	pci_chipset_tag_t psc_pc;	/* pci chipset tag */
     82  1.37.4.1      kent 	pcireg_t psc_regs[0x40>>2];	/* saved PCI config regs (sparse) */
     83      1.21   thorpej 	pcitag_t psc_tag;		/* pci device tag */
     84      1.21   thorpej 
     85      1.21   thorpej 	int psc_pwrmgmt_csr_reg;	/* ACPI power management register */
     86      1.21   thorpej 	pcireg_t psc_pwrmgmt_csr;	/* ...and the contents at D0 */
     87      1.14      fvdl };
     88      1.14      fvdl 
     89       1.1      fvdl /*
     90       1.1      fvdl  * PCI constants.
     91       1.1      fvdl  * XXX These should be in a common file!
     92       1.1      fvdl  */
     93       1.1      fvdl #define PCI_CONN		0x48    /* Connector type */
     94       1.1      fvdl #define PCI_CBIO		0x10    /* Configuration Base IO Address */
     95       1.1      fvdl #define PCI_POWERCTL		0xe0
     96      1.14      fvdl #define PCI_FUNCMEM		0x18
     97      1.14      fvdl 
     98      1.18   kanaoka #define PCI_INTR		4
     99      1.14      fvdl #define PCI_INTRACK		0x00008000
    100       1.1      fvdl 
    101      1.37   thorpej static int	ex_pci_match(struct device *, struct cfdata *, void *);
    102      1.37   thorpej static void	ex_pci_attach(struct device *, struct device *, void *);
    103      1.37   thorpej static void	ex_pci_intr_ack(struct ex_softc *);
    104       1.1      fvdl 
    105      1.37   thorpej static int	ex_pci_enable(struct ex_softc *);
    106      1.37   thorpej static void	ex_pci_disable(struct ex_softc *);
    107      1.21   thorpej 
    108      1.37   thorpej static void	ex_pci_confreg_restore(struct ex_pci_softc *);
    109      1.37   thorpej static void	ex_d3tod0( struct ex_softc *, struct pci_attach_args *);
    110      1.21   thorpej 
    111      1.26   thorpej CFATTACH_DECL(ex_pci, sizeof(struct ex_pci_softc),
    112      1.27   thorpej     ex_pci_match, ex_pci_attach, NULL, NULL);
    113       1.1      fvdl 
    114      1.37   thorpej static const struct ex_pci_product {
    115       1.3   thorpej 	u_int32_t	epp_prodid;	/* PCI product ID */
    116       1.3   thorpej 	int		epp_flags;	/* initial softc flags */
    117       1.3   thorpej 	const char	*epp_name;	/* device name */
    118       1.3   thorpej } ex_pci_products[] = {
    119       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C900TPO,	0,
    120       1.4   thorpej 	  "3c900-TPO Ethernet" },
    121       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C900COMBO,	0,
    122       1.4   thorpej 	  "3c900-COMBO Ethernet" },
    123       1.3   thorpej 
    124       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C905TX,	EX_CONF_MII,
    125       1.4   thorpej 	  "3c905-TX 10/100 Ethernet" },
    126       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C905T4,	EX_CONF_MII,
    127       1.4   thorpej 	  "3c905-T4 10/100 Ethernet" },
    128       1.3   thorpej 
    129       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C900BTPO,	EX_CONF_90XB,
    130       1.4   thorpej 	  "3c900B-TPO Ethernet" },
    131       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C900BCOMBO,	EX_CONF_90XB,
    132       1.4   thorpej 	  "3c900B-COMBO Ethernet" },
    133       1.6      fvdl 	{ PCI_PRODUCT_3COM_3C900BTPC,   EX_CONF_90XB,
    134       1.6      fvdl 	  "3c900B-TPC Ethernet" },
    135       1.3   thorpej 
    136       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C905BTX,	EX_CONF_90XB|EX_CONF_MII|EX_CONF_INTPHY,
    137       1.4   thorpej 	  "3c905B-TX 10/100 Ethernet" },
    138       1.3   thorpej 	{ PCI_PRODUCT_3COM_3C905BT4,	EX_CONF_90XB|EX_CONF_MII,
    139       1.4   thorpej 	  "3c905B-T4 10/100 Ethernet" },
    140       1.9  drochner 	{ PCI_PRODUCT_3COM_3C905BCOMBO,	EX_CONF_90XB/*|EX_CONF_MII|EX_CONF_INTPHY*/,
    141       1.9  drochner 	  "3c905B-COMBO 10/100 Ethernet" },
    142       1.8      fvdl 	{ PCI_PRODUCT_3COM_3C905BFX,	EX_CONF_90XB,
    143       1.4   thorpej 	  "3c905B-FX 10/100 Ethernet" },
    144       1.4   thorpej 
    145       1.4   thorpej 	/* XXX Internal PHY? */
    146      1.10   mycroft 	{ PCI_PRODUCT_3COM_3C980SRV,	EX_CONF_90XB,
    147       1.4   thorpej 	  "3c980 Server Adapter 10/100 Ethernet" },
    148      1.20  christos 	{ PCI_PRODUCT_3COM_3C980CTXM,	EX_CONF_90XB|EX_CONF_MII,
    149      1.12   thorpej 	  "3c980C-TXM 10/100 Ethernet" },
    150      1.12   thorpej 
    151       1.7      ross 	{ PCI_PRODUCT_3COM_3C905CTX,	EX_CONF_90XB|EX_CONF_MII,
    152       1.7      ross 	  "3c905C-TX 10/100 Ethernet with mngmt" },
    153      1.13     billc 
    154      1.13     billc 	{ PCI_PRODUCT_3COM_3C450TX,		EX_CONF_90XB,
    155      1.13     billc 	  "3c450-TX 10/100 Ethernet" },
    156      1.13     billc 
    157      1.13     billc 	{ PCI_PRODUCT_3COM_3CSOHO100TX,	EX_CONF_90XB,
    158      1.13     billc 	  "3cSOHO100-TX 10/100 Ethernet" },
    159       1.3   thorpej 
    160      1.14      fvdl 	{ PCI_PRODUCT_3COM_3C555,
    161      1.14      fvdl 	   EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
    162      1.14      fvdl 	   EX_CONF_EEPROM_8BIT,
    163      1.14      fvdl 	  "3c555 MiniPCI 10/100 Ethernet" },
    164      1.14      fvdl 
    165      1.14      fvdl 	{ PCI_PRODUCT_3COM_3C556,
    166      1.14      fvdl 	   EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
    167      1.14      fvdl 	   EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
    168      1.14      fvdl 	   EX_CONF_PHY_POWER | EX_CONF_EEPROM_8BIT,
    169      1.14      fvdl 	  "3c556 MiniPCI 10/100 Ethernet" },
    170      1.14      fvdl 
    171      1.14      fvdl 	{ PCI_PRODUCT_3COM_3C556B,
    172      1.14      fvdl 	   EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
    173      1.14      fvdl 	   EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
    174      1.35    dogcow 	   EX_CONF_PHY_POWER | EX_CONF_NO_XCVR_PWR,
    175      1.14      fvdl 	  "3c556B MiniPCI 10/100 Ethernet" },
    176      1.31  gendalia 
    177      1.31  gendalia 	{ PCI_PRODUCT_3COM_3C905CXTX,	EX_CONF_90XB|EX_CONF_MII,
    178      1.31  gendalia 	  "3c905CX-TX 10/100 Ethernet with mngmt" },
    179      1.14      fvdl 
    180      1.36  junyoung 	{ PCI_PRODUCT_3COM_3C920BEMBW,	EX_CONF_90XB|EX_CONF_MII,
    181      1.36  junyoung 	  "3c920B-EMB-WNM Integrated Fast Ethernet" },
    182      1.36  junyoung 
    183       1.3   thorpej 	{ 0,				0,
    184       1.3   thorpej 	  NULL },
    185       1.3   thorpej };
    186       1.3   thorpej 
    187      1.37   thorpej static const struct ex_pci_product *
    188      1.37   thorpej ex_pci_lookup(const struct pci_attach_args *pa)
    189       1.3   thorpej {
    190       1.3   thorpej 	const struct ex_pci_product *epp;
    191       1.3   thorpej 
    192       1.3   thorpej 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
    193       1.3   thorpej 		return (NULL);
    194       1.3   thorpej 
    195       1.3   thorpej 	for (epp = ex_pci_products; epp->epp_name != NULL; epp++)
    196       1.3   thorpej 		if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
    197       1.3   thorpej 			return (epp);
    198       1.3   thorpej 	return (NULL);
    199       1.3   thorpej }
    200       1.3   thorpej 
    201      1.37   thorpej static int
    202      1.37   thorpej ex_pci_match(struct device *parent, struct cfdata *match, void *aux)
    203       1.1      fvdl {
    204       1.1      fvdl 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    205       1.1      fvdl 
    206       1.3   thorpej 	if (ex_pci_lookup(pa) != NULL)
    207       1.3   thorpej 		return (2);	/* beat ep_pci */
    208       1.1      fvdl 
    209       1.3   thorpej 	return (0);
    210       1.1      fvdl }
    211       1.1      fvdl 
    212      1.37   thorpej static void
    213      1.37   thorpej ex_pci_attach(struct device *parent, struct device *self, void *aux)
    214       1.1      fvdl {
    215       1.1      fvdl 	struct ex_softc *sc = (void *)self;
    216      1.14      fvdl 	struct ex_pci_softc *psc = (void *)self;
    217       1.1      fvdl 	struct pci_attach_args *pa = aux;
    218       1.1      fvdl 	pci_chipset_tag_t pc = pa->pa_pc;
    219       1.1      fvdl 	pci_intr_handle_t ih;
    220       1.3   thorpej 	const struct ex_pci_product *epp;
    221       1.1      fvdl 	const char *intrstr = NULL;
    222      1.11   mycroft 	int rev, pmreg;
    223      1.11   mycroft 	pcireg_t reg;
    224       1.1      fvdl 
    225      1.32   thorpej 	aprint_naive(": Ethernet controller\n");
    226      1.32   thorpej 
    227       1.1      fvdl 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    228       1.1      fvdl 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    229      1.32   thorpej 		aprint_error(": can't map i/o space\n");
    230       1.1      fvdl 		return;
    231       1.1      fvdl 	}
    232       1.1      fvdl 
    233       1.3   thorpej 	epp = ex_pci_lookup(pa);
    234       1.3   thorpej 	if (epp == NULL) {
    235       1.3   thorpej 		printf("\n");
    236       1.3   thorpej 		panic("ex_pci_attach: impossible");
    237       1.1      fvdl 	}
    238       1.1      fvdl 
    239       1.9  drochner 	rev = PCI_REVISION(pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG));
    240      1.32   thorpej 	aprint_normal(": 3Com %s (rev. 0x%x)\n", epp->epp_name, rev);
    241       1.1      fvdl 
    242       1.3   thorpej 	sc->sc_dmat = pa->pa_dmat;
    243       1.3   thorpej 
    244       1.3   thorpej 	sc->ex_bustype = EX_BUS_PCI;
    245       1.3   thorpej 	sc->ex_conf = epp->epp_flags;
    246       1.3   thorpej 
    247       1.1      fvdl 	/* Enable the card. */
    248       1.1      fvdl 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    249       1.1      fvdl 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    250       1.1      fvdl 	    PCI_COMMAND_MASTER_ENABLE);
    251       1.1      fvdl 
    252      1.21   thorpej 	psc->psc_pc = pc;
    253      1.21   thorpej 	psc->psc_tag = pa->pa_tag;
    254  1.37.4.1      kent 	psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] =
    255      1.21   thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    256      1.21   thorpej 	psc->psc_regs[PCI_BHLC_REG>>2] =
    257  1.37.4.1      kent 	    pci_conf_read(pc, pa->pa_tag, PCI_BHLC_REG);
    258      1.21   thorpej 	psc->psc_regs[PCI_CBIO>>2] =
    259      1.21   thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_CBIO);
    260      1.21   thorpej 
    261      1.18   kanaoka 	if (sc->ex_conf & EX_CONF_PCI_FUNCREG) {
    262      1.18   kanaoka 		/* Map PCI function status window. */
    263      1.18   kanaoka 		if (pci_mapreg_map(pa, PCI_FUNCMEM, PCI_MAPREG_TYPE_MEM, 0,
    264      1.18   kanaoka 		    &psc->sc_funct, &psc->sc_funch, NULL, NULL)) {
    265      1.32   thorpej 			aprint_error(
    266      1.32   thorpej 			    "%s: unable to map function status window\n",
    267      1.18   kanaoka 			    sc->sc_dev.dv_xname);
    268      1.18   kanaoka 			return;
    269      1.18   kanaoka 		}
    270      1.18   kanaoka 		sc->intr_ack = ex_pci_intr_ack;
    271      1.21   thorpej 
    272      1.21   thorpej 		psc->psc_regs[PCI_FUNCMEM>>2] =
    273      1.21   thorpej 		    pci_conf_read(pc, pa->pa_tag, PCI_FUNCMEM);
    274      1.18   kanaoka 	}
    275      1.24   thorpej 
    276      1.24   thorpej 	psc->psc_regs[PCI_INTERRUPT_REG>>2] =
    277      1.24   thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_INTERRUPT_REG);
    278      1.24   thorpej 
    279       1.1      fvdl 	/* Get it out of power save mode if needed (BIOS bugs) */
    280      1.11   mycroft 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
    281      1.21   thorpej 		sc->enable = ex_pci_enable;
    282      1.21   thorpej 		sc->disable = ex_pci_disable;
    283      1.21   thorpej 
    284      1.28   tsutsui 		psc->psc_pwrmgmt_csr_reg = pmreg + PCI_PMCSR;
    285      1.29   tsutsui 		reg = pci_conf_read(pc, pa->pa_tag, psc->psc_pwrmgmt_csr_reg);
    286      1.21   thorpej 
    287      1.21   thorpej 		psc->psc_pwrmgmt_csr = (reg & ~PCI_PMCSR_STATE_MASK) |
    288      1.21   thorpej 		    PCI_PMCSR_STATE_D0;
    289      1.21   thorpej 
    290      1.30   tsutsui 		switch (reg & PCI_PMCSR_STATE_MASK) {
    291      1.30   tsutsui 		case PCI_PMCSR_STATE_D3:
    292      1.34  christos 			aprint_normal("%s: found in power state D3, "
    293      1.34  christos 			    "attempting to recover.\n", sc->sc_dev.dv_xname);
    294      1.34  christos 			ex_d3tod0(sc, pa);
    295      1.34  christos 			aprint_normal("%s: changed power state to D0.\n",
    296       1.1      fvdl 			    sc->sc_dev.dv_xname);
    297      1.34  christos 			break;
    298      1.30   tsutsui 		case PCI_PMCSR_STATE_D1:
    299      1.30   tsutsui 		case PCI_PMCSR_STATE_D2:
    300      1.32   thorpej 			aprint_normal("%s: waking up from power state D%d\n",
    301      1.11   mycroft 			    sc->sc_dev.dv_xname, reg);
    302      1.30   tsutsui 			pci_conf_write(pc, pa->pa_tag, pmreg + PCI_PMCSR,
    303      1.30   tsutsui 			    (reg & ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D0);
    304      1.30   tsutsui 			break;
    305       1.1      fvdl 		}
    306       1.1      fvdl 	}
    307       1.1      fvdl 
    308      1.21   thorpej 	sc->enabled = 1;
    309      1.21   thorpej 
    310       1.1      fvdl 	/* Map and establish the interrupt. */
    311      1.15  sommerfe 	if (pci_intr_map(pa, &ih)) {
    312      1.32   thorpej 		aprint_error("%s: couldn't map interrupt\n",
    313      1.32   thorpej 		    sc->sc_dev.dv_xname);
    314       1.1      fvdl 		return;
    315       1.1      fvdl 	}
    316      1.14      fvdl 
    317       1.1      fvdl 	intrstr = pci_intr_string(pc, ih);
    318       1.1      fvdl 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ex_intr, sc);
    319       1.1      fvdl 	if (sc->sc_ih == NULL) {
    320      1.32   thorpej 		aprint_error("%s: couldn't establish interrupt",
    321       1.1      fvdl 		    sc->sc_dev.dv_xname);
    322       1.1      fvdl 		if (intrstr != NULL)
    323      1.32   thorpej 			aprint_normal(" at %s", intrstr);
    324      1.32   thorpej 		aprint_normal("\n");
    325       1.1      fvdl 		return;
    326       1.1      fvdl 	}
    327      1.32   thorpej 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    328       1.1      fvdl 
    329       1.1      fvdl 	ex_config(sc);
    330      1.18   kanaoka 
    331      1.18   kanaoka 	if (sc->ex_conf & EX_CONF_PCI_FUNCREG)
    332  1.37.4.1      kent 		bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR,
    333      1.18   kanaoka 		    PCI_INTRACK);
    334      1.21   thorpej 
    335      1.21   thorpej 	if (sc->disable != NULL)
    336      1.23    itojun 		ex_disable(sc);
    337      1.14      fvdl }
    338      1.14      fvdl 
    339  1.37.4.1      kent static void
    340      1.37   thorpej ex_pci_intr_ack(struct ex_softc *sc)
    341      1.14      fvdl {
    342      1.14      fvdl 	struct ex_pci_softc *psc = (struct ex_pci_softc *)sc;
    343  1.37.4.1      kent 
    344      1.18   kanaoka 	bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR,
    345      1.14      fvdl 	    PCI_INTRACK);
    346      1.33  christos }
    347      1.33  christos 
    348      1.37   thorpej static void
    349      1.37   thorpej ex_d3tod0(struct ex_softc *sc, struct pci_attach_args *pa)
    350      1.33  christos {
    351      1.33  christos 
    352      1.33  christos #define PCI_CACHE_LAT_BIST	0x0c
    353      1.33  christos #define PCI_BAR0		0x10
    354      1.33  christos #define PCI_BAR1		0x14
    355      1.33  christos #define PCI_BAR2		0x18
    356      1.33  christos #define PCI_BAR3		0x1C
    357      1.33  christos #define PCI_BAR4		0x20
    358      1.33  christos #define PCI_BAR5		0x24
    359      1.33  christos #define PCI_EXP_ROM_BAR		0x30
    360      1.33  christos #define PCI_INT_GNT_LAT		0x3c
    361      1.33  christos 
    362      1.33  christos 	pci_chipset_tag_t pc = pa->pa_pc;
    363      1.33  christos 
    364      1.33  christos 	u_int32_t base0;
    365      1.33  christos 	u_int32_t base1;
    366      1.33  christos 	u_int32_t romaddr;
    367      1.33  christos 	u_int32_t pci_command;
    368      1.33  christos 	u_int32_t pci_int_lat;
    369      1.33  christos 	u_int32_t pci_cache_lat;
    370      1.33  christos 
    371      1.33  christos 	pci_command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    372      1.33  christos 	base0 = pci_conf_read(pc, pa->pa_tag, PCI_BAR0);
    373      1.33  christos 	base1 = pci_conf_read(pc, pa->pa_tag, PCI_BAR1);
    374      1.33  christos 	romaddr	= pci_conf_read(pc, pa->pa_tag, PCI_EXP_ROM_BAR);
    375      1.33  christos 	pci_cache_lat= pci_conf_read(pc, pa->pa_tag, PCI_CACHE_LAT_BIST);
    376      1.33  christos 	pci_int_lat = pci_conf_read(pc, pa->pa_tag, PCI_INT_GNT_LAT);
    377      1.33  christos 
    378      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_POWERCTL, 0);
    379      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_BAR0, base0);
    380      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_BAR1, base1);
    381      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_EXP_ROM_BAR, romaddr);
    382      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_INT_GNT_LAT, pci_int_lat);
    383      1.33  christos 	pci_conf_write(pc, pa->pa_tag, PCI_CACHE_LAT_BIST, pci_cache_lat);
    384  1.37.4.1      kent 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    385      1.33  christos 	    (PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE));
    386      1.21   thorpej }
    387      1.21   thorpej 
    388      1.37   thorpej static void
    389      1.37   thorpej ex_pci_confreg_restore(struct ex_pci_softc *psc)
    390      1.21   thorpej {
    391      1.21   thorpej 	struct ex_softc *sc = (void *) psc;
    392      1.21   thorpej 	pcireg_t reg;
    393      1.21   thorpej 
    394      1.21   thorpej 	reg = pci_conf_read(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG);
    395      1.21   thorpej 
    396      1.21   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag,
    397      1.21   thorpej 	    PCI_COMMAND_STATUS_REG,
    398      1.21   thorpej 	    (reg & 0xffff0000) |
    399      1.21   thorpej 	    (psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] & 0xffff));
    400      1.21   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_BHLC_REG,
    401      1.21   thorpej 	    psc->psc_regs[PCI_BHLC_REG>>2]);
    402      1.21   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_CBIO,
    403      1.21   thorpej 	    psc->psc_regs[PCI_CBIO>>2]);
    404      1.21   thorpej 	if (sc->ex_conf & EX_CONF_PCI_FUNCREG)
    405      1.21   thorpej 		pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_FUNCMEM,
    406      1.21   thorpej 		    psc->psc_regs[PCI_FUNCMEM>>2]);
    407      1.24   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_INTERRUPT_REG,
    408      1.24   thorpej 	    psc->psc_regs[PCI_INTERRUPT_REG>>2]);
    409      1.21   thorpej }
    410      1.21   thorpej 
    411      1.37   thorpej static int
    412      1.37   thorpej ex_pci_enable(struct ex_softc *sc)
    413      1.21   thorpej {
    414      1.21   thorpej 	struct ex_pci_softc *psc = (void *) sc;
    415      1.21   thorpej 
    416      1.21   thorpej #if 0
    417      1.21   thorpej 	printf("%s: going to power state D0\n", sc->sc_dev.dv_xname);
    418      1.21   thorpej #endif
    419      1.21   thorpej 
    420      1.21   thorpej 	/* Bring the device into D0 power state. */
    421      1.21   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag,
    422      1.21   thorpej 	    psc->psc_pwrmgmt_csr_reg, psc->psc_pwrmgmt_csr);
    423      1.21   thorpej 
    424      1.21   thorpej 	/* Now restore the configuration registers. */
    425      1.21   thorpej 	ex_pci_confreg_restore(psc);
    426      1.21   thorpej 
    427      1.21   thorpej 	return (0);
    428      1.21   thorpej }
    429      1.21   thorpej 
    430      1.37   thorpej static void
    431      1.37   thorpej ex_pci_disable(struct ex_softc *sc)
    432      1.21   thorpej {
    433      1.21   thorpej 	struct ex_pci_softc *psc = (void *) sc;
    434      1.21   thorpej 
    435      1.21   thorpej #if 0
    436      1.21   thorpej 	printf("%s: going to power state D3\n", sc->sc_dev.dv_xname);
    437      1.21   thorpej #endif
    438      1.21   thorpej 
    439      1.21   thorpej 	/* Put the device into D3 state. */
    440      1.21   thorpej 	pci_conf_write(psc->psc_pc, psc->psc_tag,
    441      1.21   thorpej 	    psc->psc_pwrmgmt_csr_reg, (psc->psc_pwrmgmt_csr &
    442      1.21   thorpej 	    ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D3);
    443       1.1      fvdl }
    444