Module Name:    src
Committed By:   dyoung
Date:           Mon Mar 22 16:17:43 UTC 2010

Modified Files:
        src/sys/dev/pci: if_fxp_pci.c

Log Message:
Add a detach routine.  Enable detachment at shutdown.

psc_pwrmgmt_csr_reg was never initialized to the actual offset of the
PCI PMCSR!  Just delete psc_pwrmgmt_csr_reg and all uses of it.  In
this way, fxp_pci_disable() becomes a no-op, so delete it, too.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/pci/if_fxp_pci.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_fxp_pci.c
diff -u src/sys/dev/pci/if_fxp_pci.c:1.73 src/sys/dev/pci/if_fxp_pci.c:1.74
--- src/sys/dev/pci/if_fxp_pci.c:1.73	Wed Feb 24 22:38:00 2010
+++ src/sys/dev/pci/if_fxp_pci.c	Mon Mar 22 16:17:43 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_fxp_pci.c,v 1.73 2010/02/24 22:38:00 dyoung Exp $	*/
+/*	$NetBSD: if_fxp_pci.c,v 1.74 2010/03/22 16:17:43 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_fxp_pci.c,v 1.73 2010/02/24 22:38:00 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_fxp_pci.c,v 1.74 2010/03/22 16:17:43 dyoung Exp $");
 
 #include "rnd.h"
 
@@ -80,22 +80,21 @@
 	pcireg_t psc_regs[0x20>>2];	/* saved PCI config regs (sparse) */
 	pcitag_t psc_tag;		/* pci register tag */
 
-	int psc_pwrmgmt_csr_reg;	/* ACPI power management register */
-	pcireg_t psc_pwrmgmt_csr;	/* ...and the contents at D0 */
 	struct pci_conf_state psc_pciconf; /* standard PCI configuration regs */
 };
 
 static int	fxp_pci_match(device_t, cfdata_t, void *);
 static void	fxp_pci_attach(device_t, device_t, void *);
+static int	fxp_pci_detach(device_t, int);
 
 static int	fxp_pci_enable(struct fxp_softc *);
-static void	fxp_pci_disable(struct fxp_softc *);
 
 static void fxp_pci_confreg_restore(struct fxp_pci_softc *psc);
 static bool fxp_pci_resume(device_t dv, const pmf_qual_t *);
 
-CFATTACH_DECL_NEW(fxp_pci, sizeof(struct fxp_pci_softc),
-    fxp_pci_match, fxp_pci_attach, NULL, NULL);
+CFATTACH_DECL3_NEW(fxp_pci, sizeof(struct fxp_pci_softc),
+    fxp_pci_match, fxp_pci_attach, fxp_pci_detach, NULL, NULL,
+    null_childdetached, DVF_DETACH_SHUTDOWN);
 
 static const struct fxp_pci_product {
 	uint32_t	fpp_prodid;	/* PCI product ID */
@@ -243,6 +242,26 @@
 	return true;
 }
 
+static int
+fxp_pci_detach(device_t self, int flags)
+{
+	struct fxp_pci_softc *psc = device_private(self);
+	struct fxp_softc *sc = &psc->psc_fxp;
+	int error;
+
+	/* Finish off the attach. */
+	if ((error = fxp_detach(sc, flags)) != 0)
+		return error;
+
+	pmf_device_deregister(self);
+
+	pci_intr_disestablish(psc->psc_pc, sc->sc_ih);
+
+	bus_space_unmap(sc->sc_st, sc->sc_sh, sc->sc_size);
+
+	return 0;
+}
+
 static void
 fxp_pci_attach(device_t parent, device_t self, void *aux)
 {
@@ -258,7 +277,6 @@
 	bus_space_handle_t ioh, memh;
 	int ioh_valid, memh_valid;
 	bus_addr_t addr;
-	bus_size_t size;
 	int flags;
 	int error;
 
@@ -300,9 +318,9 @@
 	if (((pa->pa_flags & PCI_FLAGS_MEM_ENABLED) != 0) &&
 	    pci_mapreg_info(pa->pa_pc, pa->pa_tag, FXP_PCI_MMBA,
 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
-	    &addr, &size, &flags) == 0) {
+	    &addr, &sc->sc_size, &flags) == 0) {
 		flags &= ~BUS_SPACE_MAP_PREFETCHABLE;
-		if (bus_space_map(memt, addr, size, flags, &memh) == 0)
+		if (bus_space_map(memt, addr, sc->sc_size, flags, &memh) == 0)
 			memh_valid = 1;
 	}
 
@@ -446,7 +464,7 @@
 		break;
 	case 0: 
 		sc->sc_enable = fxp_pci_enable;
-		sc->sc_disable = fxp_pci_disable;
+		sc->sc_disable = NULL;
 		break;
 	default:
 		aprint_error_dev(self, "cannot activate %d\n", error);
@@ -497,34 +515,8 @@
 	printf("%s: going to power state D0\n", device_xname(self));
 #endif
 
-	/* Bring the device into D0 power state. */
-	pci_conf_write(psc->psc_pc, psc->psc_tag,
-	    psc->psc_pwrmgmt_csr_reg, psc->psc_pwrmgmt_csr);
-
 	/* Now restore the configuration registers. */
 	fxp_pci_confreg_restore(psc);
 
 	return (0);
 }
-
-static void
-fxp_pci_disable(struct fxp_softc *sc)
-{
-	struct fxp_pci_softc *psc = (void *) sc;
-
-	/*
-	 * for some 82558_A4 and 82558_B0, entering D3 state makes
-	 * media detection disordered.
-	 */
-	if (sc->sc_rev <= FXP_REV_82558_B0)
-		return;
-
-#if 0
-	printf("%s: going to power state D3\n", device_xname(self));
-#endif
-
-	/* Put the device into D3 state. */
-	pci_conf_write(psc->psc_pc, psc->psc_tag,
-	    psc->psc_pwrmgmt_csr_reg, (psc->psc_pwrmgmt_csr &
-	    ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D3);
-}

Reply via email to