Subject: RFC: Powerhook debugging
To: None <tech-kern@NetBSD.org>
From: Jared D. McNeill <jmcneill@invisible.ca>
List: tech-kern
Date: 09/21/2006 20:47:15
--Apple-Mail-5-186608979
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed

Heyas folks --

After upgrading my Vaio from 3.99.21 to 4.99.2, I noticed that it can  
no longer survive an S3 suspend.

I wanted a way to debug powerhooks, but this required modifying the  
powerhook_establish signature to add a "name" argument. Is the  
attached diff OK to commit?

In a nutshell, it adds an option POWERHOOK_DEBUG, which enables  
printing of powerhook names as they're being run. All consumers of  
powerhook_establish are also modified in this patch to pass a proper  
name as well.

Cheers,
Jared


--Apple-Mail-5-186608979
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name=powerhook.diff
Content-Disposition: attachment;
	filename=powerhook.diff

Index: share/man/man9/powerhook_establish.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/powerhook_establish.9,v
retrieving revision 1.5
diff -u -r1.5 powerhook_establish.9
--- share/man/man9/powerhook_establish.9	9 Dec 2002 13:22:48 -0000	1.5
+++ share/man/man9/powerhook_establish.9	21 Sep 2006 23:42:34 -0000
@@ -43,7 +43,7 @@
 .Nd add or remove a power change hook
 .Sh SYNOPSIS
 .Ft void *
-.Fn powerhook_establish "void (*fn)(int why, void *a)" "void *arg"
+.Fn powerhook_establish "char *name" "void (*fn)(int why, void *a)" "void *arg"
 .Ft void
 .Fn powerhook_disestablish "void *cookie"
 .Sh DESCRIPTION
Index: sys/arch/hpcarm/dev/sed_saip.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcarm/dev/sed_saip.c,v
retrieving revision 1.20
diff -u -r1.20 sed_saip.c
--- sys/arch/hpcarm/dev/sed_saip.c	27 Jun 2006 13:30:19 -0000	1.20
+++ sys/arch/hpcarm/dev/sed_saip.c	21 Sep 2006 23:42:37 -0000
@@ -153,7 +153,8 @@
 
 	/* Add a suspend hook to power saving */
 	sc->sc_powerstate = 0;
-	sc->sc_powerhook = powerhook_establish(sed1356_power, sc);
+	sc->sc_powerhook = powerhook_establish(self->dv_xname,
+	    sed1356_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/hpcmips/dev/ite8181.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/dev/ite8181.c,v
retrieving revision 1.23
diff -u -r1.23 ite8181.c
--- sys/arch/hpcmips/dev/ite8181.c	26 May 2006 11:56:26 -0000	1.23
+++ sys/arch/hpcmips/dev/ite8181.c	21 Sep 2006 23:42:37 -0000
@@ -277,7 +277,8 @@
 	ite8181_erase_cursor(sc);
 
 	/* Add a power hook to power saving */
-	sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ite8181_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/hpcmips/dev/mq200.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/dev/mq200.c,v
retrieving revision 1.26
diff -u -r1.26 mq200.c
--- sys/arch/hpcmips/dev/mq200.c	26 May 2006 11:57:25 -0000	1.26
+++ sys/arch/hpcmips/dev/mq200.c	21 Sep 2006 23:42:37 -0000
@@ -199,7 +199,8 @@
 
 	/* Add a power hook to power saving */
 	sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
-	sc->sc_powerhook = powerhook_establish(mq200_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    mq200_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/hpcmips/vr/vrpiu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/vr/vrpiu.c,v
retrieving revision 1.36
diff -u -r1.36 vrpiu.c
--- sys/arch/hpcmips/vr/vrpiu.c	26 May 2006 12:02:26 -0000	1.36
+++ sys/arch/hpcmips/vr/vrpiu.c	21 Sep 2006 23:42:38 -0000
@@ -330,7 +330,11 @@
 	/*
 	 * power management events
 	 */
-	sc->sc_power_hook = powerhook_establish(vrpiu_power, sc);
+	sc->sc_power_hook = powerhook_establish(sc->sc_dev.dv_xname,
+	    vrpiu_power, sc);
+	if (sc->sc_power_hook == NULL)
+		aprint_error("%s: WARNING: couldn't establish powerhook\n",
+		    sc->sc_dev.dv_xname);
 
 	/*
 	 * init A/D port polling.
Index: sys/arch/hpcsh/dev/j6x0tp.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcsh/dev/j6x0tp.c,v
retrieving revision 1.11
diff -u -r1.11 j6x0tp.c
--- sys/arch/hpcsh/dev/j6x0tp.c	23 May 2006 01:34:49 -0000	1.11
+++ sys/arch/hpcsh/dev/j6x0tp.c	21 Sep 2006 23:42:38 -0000
@@ -622,6 +622,11 @@
 	delay(10);
 
 	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
+	printf("[1] rawxp=0x%x\n", *rawxp);
+	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
+	printf("[1] rawxp=0x%x\n", *rawxp);
+	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
+	printf("[1] rawxp=0x%x\n", *rawxp);
 
 	/* X axis */
 	scpdr = _reg_read_1(SH7709_SCPDR);
Index: sys/arch/i386/bios/vesafb.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/bios/vesafb.c,v
retrieving revision 1.16
diff -u -r1.16 vesafb.c
--- sys/arch/i386/bios/vesafb.c	3 Sep 2006 21:05:01 -0000	1.16
+++ sys/arch/i386/bios/vesafb.c	21 Sep 2006 23:42:38 -0000
@@ -308,7 +308,8 @@
 
 	sc->sc_isconsole = 1;
 
-	sc->sc_powerhook = powerhook_establish(vesafb_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    vesafb_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: unable to establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/i386/pci/ichlpcib.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/pci/ichlpcib.c,v
retrieving revision 1.15
diff -u -r1.15 ichlpcib.c
--- sys/arch/i386/pci/ichlpcib.c	19 Jun 2006 10:08:16 -0000	1.15
+++ sys/arch/i386/pci/ichlpcib.c	21 Sep 2006 23:42:39 -0000
@@ -156,7 +156,8 @@
 	speedstep_configure(sc, pa);
 
 	/* Install powerhook */
-	sc->sc_powerhook = powerhook_establish(lpcib_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    lpcib_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: can't establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/i386/pci/piixpcib.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/pci/piixpcib.c,v
retrieving revision 1.7
diff -u -r1.7 piixpcib.c
--- sys/arch/i386/pci/piixpcib.c	22 Jun 2006 16:24:34 -0000	1.7
+++ sys/arch/i386/pci/piixpcib.c	21 Sep 2006 23:42:39 -0000
@@ -156,7 +156,8 @@
 		return;
 	}
 
-	sc->sc_powerhook = powerhook_establish(piixpcib_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    piixpcib_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: can't establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/arch/macppc/dev/if_wi_obio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/macppc/dev/if_wi_obio.c,v
retrieving revision 1.12
diff -u -r1.12 if_wi_obio.c
--- sys/arch/macppc/dev/if_wi_obio.c	11 Dec 2005 12:18:03 -0000	1.12
+++ sys/arch/macppc/dev/if_wi_obio.c	21 Sep 2006 23:42:39 -0000
@@ -115,7 +115,8 @@
 	}
 
 	sc->sc_sdhook = shutdownhook_establish(wi_obio_shutdown, sc);
-	sc->sc_powerhook = powerhook_establish(wi_obio_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(self->dv_xname,
+	    wi_obio_powerhook, sc);
 
 	/* Disable the card. */
 	wisc->sc_enabled = 0;
Index: sys/arch/mips/atheros/dev/if_ae.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/atheros/dev/if_ae.c,v
retrieving revision 1.3
diff -u -r1.3 if_ae.c
--- sys/arch/mips/atheros/dev/if_ae.c	4 Sep 2006 05:17:26 -0000	1.3
+++ sys/arch/mips/atheros/dev/if_ae.c	21 Sep 2006 23:42:40 -0000
@@ -414,7 +414,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(ae_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ae_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/audio.c
===================================================================
RCS file: /cvsroot/src/sys/dev/audio.c,v
retrieving revision 1.209
diff -u -r1.209 audio.c
--- sys/dev/audio.c	27 Aug 2006 23:54:50 -0000	1.209
+++ sys/dev/audio.c	21 Sep 2006 23:42:46 -0000
@@ -455,7 +455,8 @@
 		 sc->sc_inports.allports, sc->sc_inports.master,
 		 sc->sc_outports.allports, sc->sc_outports.master));
 
-	sc->sc_powerhook = powerhook_establish(audio_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->dev.dv_xname,
+	    audio_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: can't establish powerhook\n",
 		    sc->dev.dv_xname);
Index: sys/dev/acpi/acpi_pci_link.c
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/acpi_pci_link.c,v
retrieving revision 1.4
diff -u -r1.4 acpi_pci_link.c
--- sys/dev/acpi/acpi_pci_link.c	20 Aug 2006 15:10:59 -0000	1.4
+++ sys/dev/acpi/acpi_pci_link.c	21 Sep 2006 23:42:46 -0000
@@ -1072,7 +1072,8 @@
 	if (AcpiGbl_FADT->SciInt < NUM_ISA_INTERRUPTS)
 		pci_link_bios_isa_irqs |= (1 << AcpiGbl_FADT->SciInt);
 
-        sc->pl_powerhook = powerhook_establish(acpi_pci_link_resume, sc);
+        sc->pl_powerhook = powerhook_establish("acpi_pci_link",
+	    acpi_pci_link_resume, sc);
         if (sc->pl_powerhook == NULL)
                 aprint_normal("can't establish powerhook\n");
 
Index: sys/dev/ata/ata.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/ata.c,v
retrieving revision 1.76
diff -u -r1.76 ata.c
--- sys/dev/ata/ata.c	7 Sep 2006 12:34:42 -0000	1.76
+++ sys/dev/ata/ata.c	21 Sep 2006 23:42:47 -0000
@@ -429,7 +429,8 @@
 	config_pending_incr();
 	kthread_create(atabus_create_thread, sc);
 
-	sc->sc_powerhook = powerhook_establish(atabus_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    atabus_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/hpc/bivideo.c
===================================================================
RCS file: /cvsroot/src/sys/dev/hpc/bivideo.c,v
retrieving revision 1.22
diff -u -r1.22 bivideo.c
--- sys/dev/hpc/bivideo.c	29 Mar 2006 06:37:35 -0000	1.22
+++ sys/dev/hpc/bivideo.c	21 Sep 2006 23:42:47 -0000
@@ -174,7 +174,8 @@
 
 	/* Add a suspend hook to power saving */
 	sc->sc_powerstate = 0;
-	sc->sc_powerhook = powerhook_establish(bivideo_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    bivideo_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/hpc/hpcfb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/hpc/hpcfb.c,v
retrieving revision 1.36
diff -u -r1.36 hpcfb.c
--- sys/dev/hpc/hpcfb.c	12 Apr 2006 19:38:23 -0000	1.36
+++ sys/dev/hpc/hpcfb.c	21 Sep 2006 23:42:47 -0000
@@ -320,7 +320,8 @@
 	callout_init(&sc->sc_switch_callout);
 
 	/* Add a power hook to power management */
-	sc->sc_powerhook = powerhook_establish(hpcfb_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    hpcfb_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/ath.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/ath.c,v
retrieving revision 1.76
diff -u -r1.76 ath.c
--- sys/dev/ic/ath.c	14 Jul 2006 13:37:25 -0000	1.76
+++ sys/dev/ic/ath.c	21 Sep 2006 23:42:49 -0000
@@ -640,7 +640,8 @@
 
 #ifdef __NetBSD__
 	sc->sc_flags |= ATH_ATTACHED;
-	sc->sc_powerhook = powerhook_establish(ath_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ath_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/ic/atw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/atw.c,v
retrieving revision 1.119
diff -u -r1.119 atw.c
--- sys/dev/ic/atw.c	31 Aug 2006 19:24:37 -0000	1.119
+++ sys/dev/ic/atw.c	21 Sep 2006 23:42:50 -0000
@@ -872,7 +872,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(atw_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    atw_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/awi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/awi.c,v
retrieving revision 1.71
diff -u -r1.71 awi.c
--- sys/dev/ic/awi.c	28 Aug 2006 00:03:15 -0000	1.71
+++ sys/dev/ic/awi.c	21 Sep 2006 23:42:51 -0000
@@ -352,7 +352,8 @@
 	if ((sc->sc_sdhook = shutdownhook_establish(awi_shutdown, sc)) == NULL)
 		printf("%s: WARNING: unable to establish shutdown hook\n",
 		    ifp->if_xname);
-	if ((sc->sc_powerhook = powerhook_establish(awi_power, sc)) == NULL)
+	if ((sc->sc_powerhook =
+	     powerhook_establish(ifp->if_xname, awi_power, sc)) == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    ifp->if_xname);
 #endif
Index: sys/dev/ic/com.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/com.c,v
retrieving revision 1.251
diff -u -r1.251 com.c
--- sys/dev/ic/com.c	8 Aug 2006 10:32:09 -0000	1.251
+++ sys/dev/ic/com.c	21 Sep 2006 23:42:51 -0000
@@ -568,7 +568,8 @@
 
 	com_config(sc);
 
-	sc->sc_powerhook = powerhook_establish(com_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    com_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/ic/cs89x0.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/cs89x0.c,v
retrieving revision 1.19
diff -u -r1.19 cs89x0.c
--- sys/dev/ic/cs89x0.c	18 Mar 2006 18:44:16 -0000	1.19
+++ sys/dev/ic/cs89x0.c	21 Sep 2006 23:42:52 -0000
@@ -517,7 +517,8 @@
 		return 1;
 	}
 
-	sc->sc_powerhook = powerhook_establish(cs_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    cs_power, sc);
 	if (sc->sc_powerhook == 0)
 		printf("%s: warning: powerhook_establish failed\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/ic/elinkxl.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/elinkxl.c,v
retrieving revision 1.88
diff -u -r1.88 elinkxl.c
--- sys/dev/ic/elinkxl.c	21 May 2006 23:56:09 -0000	1.88
+++ sys/dev/ic/elinkxl.c	21 Sep 2006 23:42:52 -0000
@@ -466,7 +466,8 @@
 			sc->sc_dev.dv_xname);
 
 	/* Add a suspend hook to make sure we come back up after a resume. */
-	sc->sc_powerhook = powerhook_establish(ex_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ex_power, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/ic/gem.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/gem.c,v
retrieving revision 1.47
diff -u -r1.47 gem.c
--- sys/dev/ic/gem.c	5 Aug 2006 21:26:49 -0000	1.47
+++ sys/dev/ic/gem.c	21 Sep 2006 23:42:55 -0000
@@ -436,7 +436,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(gem_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    gem_power, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/i82365.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/i82365.c,v
retrieving revision 1.94
diff -u -r1.94 i82365.c
--- sys/dev/ic/i82365.c	14 Apr 2006 20:48:53 -0000	1.94
+++ sys/dev/ic/i82365.c	21 Sep 2006 23:42:55 -0000
@@ -470,7 +470,7 @@
 	 * (this works around a bug seen in suspend-to-disk on the
 	 * Sony VAIO Z505; on resume, the CSC_INTR state is not preserved).
 	 */
-	powerhook_establish(pcic_power, h);
+	powerhook_establish(h->ph_parent->dv_xname, pcic_power, h);
 
 	/* enable interrupts on card detect, poll for them if no irq avail */
 	reg = PCIC_CSC_INTR_CD_ENABLE;
Index: sys/dev/ic/i82557.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/i82557.c,v
retrieving revision 1.97
diff -u -r1.97 i82557.c
--- sys/dev/ic/i82557.c	20 Feb 2006 16:50:37 -0000	1.97
+++ sys/dev/ic/i82557.c	21 Sep 2006 23:42:56 -0000
@@ -450,7 +450,8 @@
 	/*
   	 * Add suspend hook, for similar reasons..
 	 */
-	sc->sc_powerhook = powerhook_establish(fxp_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    fxp_power, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/rtl8169.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl8169.c,v
retrieving revision 1.25
diff -u -r1.25 rtl8169.c
--- sys/dev/ic/rtl8169.c	18 Jun 2006 16:14:10 -0000	1.25
+++ sys/dev/ic/rtl8169.c	21 Sep 2006 23:42:57 -0000
@@ -808,7 +808,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(re_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    re_power, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/rtl81x9.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9.c,v
retrieving revision 1.52
diff -u -r1.52 rtl81x9.c
--- sys/dev/ic/rtl81x9.c	8 Dec 2005 18:06:42 -0000	1.52
+++ sys/dev/ic/rtl81x9.c	21 Sep 2006 23:42:57 -0000
@@ -772,7 +772,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(rtk_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    rtk_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ic/rtw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtw.c,v
retrieving revision 1.76
diff -u -r1.76 rtw.c
--- sys/dev/ic/rtw.c	3 Sep 2006 05:10:24 -0000	1.76
+++ sys/dev/ic/rtw.c	21 Sep 2006 23:42:59 -0000
@@ -3843,7 +3843,7 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	hooks->rh_power = powerhook_establish(rtw_power, arg);
+	hooks->rh_power = powerhook_establish(dvname, rtw_power, arg);
 	if (hooks->rh_power == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    dvname);
Index: sys/dev/ic/tulip.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/tulip.c,v
retrieving revision 1.146
diff -u -r1.146 tulip.c
--- sys/dev/ic/tulip.c	30 Aug 2006 23:31:08 -0000	1.146
+++ sys/dev/ic/tulip.c	21 Sep 2006 23:43:00 -0000
@@ -551,7 +551,8 @@
 	 * Add a suspend hook to make sure we come back up after a
 	 * resume.
 	 */
-	sc->sc_powerhook = powerhook_establish(tlp_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    tlp_power, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/ieee1394/fw_port.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ieee1394/fw_port.h,v
retrieving revision 1.16
diff -u -r1.16 fw_port.h
--- sys/dev/ieee1394/fw_port.h	30 Aug 2006 01:59:06 -0000	1.16
+++ sys/dev/ieee1394/fw_port.h	21 Sep 2006 23:43:01 -0000
@@ -748,7 +748,8 @@
 		struct fwbus_attach_args faa;				      \
 		faa.name = "ieee1394if";				      \
 		sc->sc_shutdownhook = shutdownhook_establish(fwohci_stop, sc);\
-		sc->sc_powerhook = powerhook_establish(fwohci_power, sc);     \
+		sc->sc_powerhook = powerhook_establish(sc->fc._dev.dv_xname,  \
+		    fwohci_power, sc);					      \
 		sc->fc.bdev = config_found(sc->fc.dev, &faa, fwohci_print);   \
 	} while (/*CONSTCOND*/0)
 #define FWOHCI_DETACH()	\
Index: sys/dev/isa/sbdsp.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/sbdsp.c,v
retrieving revision 1.123
diff -u -r1.123 sbdsp.c
--- sys/dev/isa/sbdsp.c	3 Sep 2006 05:16:01 -0000	1.123
+++ sys/dev/isa/sbdsp.c	21 Sep 2006 23:43:01 -0000
@@ -441,7 +441,7 @@
 		}
 	}
 
-	powerhook_establish (sbdsp_powerhook, sc);
+	powerhook_establish(sc->sc_dev.dv_xname, sbdsp_powerhook, sc);
 }
 
 static void
Index: sys/dev/isa/ym.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/ym.c,v
retrieving revision 1.28
diff -u -r1.28 ym.c
--- sys/dev/isa/ym.c	3 Sep 2006 21:47:34 -0000	1.28
+++ sys/dev/isa/ym.c	21 Sep 2006 23:43:02 -0000
@@ -307,7 +307,7 @@
 #endif
 	ym_powerdown_blocks(sc);
 
-	powerhook_establish(ym_power_hook, sc);
+	powerhook_establish(DVNAME(sc), ym_power_hook, sc);
 #endif
 
 	/* Set tone control to the default position. */
Index: sys/dev/pci/agp_i810.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/agp_i810.c,v
retrieving revision 1.32
diff -u -r1.32 agp_i810.c
--- sys/dev/pci/agp_i810.c	30 Jul 2006 04:23:44 -0000	1.32
+++ sys/dev/pci/agp_i810.c	21 Sep 2006 23:43:02 -0000
@@ -401,7 +401,8 @@
 	 */
 	agp_flush_cache();
 
-	isc->sc_powerhook = powerhook_establish(agp_i810_powerhook, sc);
+	isc->sc_powerhook = powerhook_establish(sc->as_dev.dv_xname,
+	    agp_i810_powerhook, sc);
 	if (isc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish PCI power hook\n",
 		    sc->as_dev.dv_xname);
Index: sys/dev/pci/agp_intel.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/agp_intel.c,v
retrieving revision 1.18
diff -u -r1.18 agp_intel.c
--- sys/dev/pci/agp_intel.c	11 Mar 2006 02:35:06 -0000	1.18
+++ sys/dev/pci/agp_intel.c	21 Sep 2006 23:43:02 -0000
@@ -258,7 +258,8 @@
 			AGP_INTEL_ERRSTS, 0x70);
 	}
 
-	isc->sc_powerhook = powerhook_establish(agp_intel_powerhook, sc);
+	isc->sc_powerhook = powerhook_establish(sc->as_dev.dv_xname,
+	    agp_intel_powerhook, sc);
 	if (isc->sc_powerhook == NULL)
 		aprint_error("%s: couldn't establish powerhook\n",
 		    sc->as_dev.dv_xname);
Index: sys/dev/pci/auacer.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auacer.c,v
retrieving revision 1.12
diff -u -r1.12 auacer.c
--- sys/dev/pci/auacer.c	27 Aug 2006 23:53:10 -0000	1.12
+++ sys/dev/pci/auacer.c	21 Sep 2006 23:43:03 -0000
@@ -351,7 +351,8 @@
 
 	/* Watch for power change */
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(auacer_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    auacer_powerhook, sc);
 
 	audio_attach_mi(&auacer_hw_if, sc, &sc->sc_dev);
 
Index: sys/dev/pci/auich.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auich.c,v
retrieving revision 1.111
diff -u -r1.111 auich.c
--- sys/dev/pci/auich.c	3 Aug 2006 03:01:39 -0000	1.111
+++ sys/dev/pci/auich.c	21 Sep 2006 23:43:03 -0000
@@ -645,7 +645,8 @@
 
 	/* Watch for power change */
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(auich_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    auich_powerhook, sc);
 
 	config_interrupts(self, auich_finish_attach);
 
Index: sys/dev/pci/auixp.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auixp.c,v
retrieving revision 1.16
diff -u -r1.16 auixp.c
--- sys/dev/pci/auixp.c	27 Aug 2006 23:59:40 -0000	1.16
+++ sys/dev/pci/auixp.c	21 Sep 2006 23:43:04 -0000
@@ -1228,7 +1228,8 @@
 		return;
 	}
 
-	sc->powerhook = powerhook_establish(auixp_powerhook, sc);
+	sc->powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    auixp_powerhook, sc);
 	if (sc->powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/autri.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/autri.c,v
retrieving revision 1.31
diff -u -r1.31 autri.c
--- sys/dev/pci/autri.c	28 Aug 2006 00:01:36 -0000	1.31
+++ sys/dev/pci/autri.c	21 Sep 2006 23:43:04 -0000
@@ -598,7 +598,7 @@
 #endif
 
 	sc->sc_old_power = PWR_RESUME;
-	powerhook_establish(autri_powerhook, sc);
+	powerhook_establish(sc->sc_dev.dv_xname, autri_powerhook, sc);
 }
 
 CFATTACH_DECL(autri, sizeof(struct autri_softc),
Index: sys/dev/pci/auvia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auvia.c,v
retrieving revision 1.55
diff -u -r1.55 auvia.c
--- sys/dev/pci/auvia.c	28 Aug 2006 00:02:21 -0000	1.55
+++ sys/dev/pci/auvia.c	21 Sep 2006 23:43:04 -0000
@@ -454,7 +454,8 @@
 
 	/* Watch for power change */
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(auvia_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    auvia_powerhook, sc);
 
 	audio_attach_mi(&auvia_hw_if, sc, &sc->sc_dev);
 	sc->codec_if->vtbl->unlock(sc->codec_if);
Index: sys/dev/pci/cs4280.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/cs4280.c,v
retrieving revision 1.42
diff -u -r1.42 cs4280.c
--- sys/dev/pci/cs4280.c	29 Aug 2006 23:53:06 -0000	1.42
+++ sys/dev/pci/cs4280.c	21 Sep 2006 23:43:05 -0000
@@ -362,7 +362,8 @@
 #endif
 
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(cs4280_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    cs4280_power, sc);
 }
 
 /* Interrupt handling function */
Index: sys/dev/pci/cs4281.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/cs4281.c,v
retrieving revision 1.30
diff -u -r1.30 cs4281.c
--- sys/dev/pci/cs4281.c	29 Aug 2006 23:54:10 -0000	1.30
+++ sys/dev/pci/cs4281.c	21 Sep 2006 23:43:05 -0000
@@ -289,7 +289,8 @@
 #endif
 
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(cs4281_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    cs4281_power, sc);
 }
 
 static int
Index: sys/dev/pci/ehci_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/ehci_pci.c,v
retrieving revision 1.23
diff -u -r1.23 ehci_pci.c
--- sys/dev/pci/ehci_pci.c	10 Mar 2006 17:21:20 -0000	1.23
+++ sys/dev/pci/ehci_pci.c	21 Sep 2006 23:43:05 -0000
@@ -208,7 +208,8 @@
 		return;
 	}
 
-	sc->sc_powerhook = powerhook_establish(ehci_pci_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(
+	    USBDEVNAME(sc->sc.sc_bus.bdev) , ehci_pci_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: couldn't establish powerhook\n",
 		    devname);
Index: sys/dev/pci/esa.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esa.c,v
retrieving revision 1.34
diff -u -r1.34 esa.c
--- sys/dev/pci/esa.c	30 Aug 2006 00:54:28 -0000	1.34
+++ sys/dev/pci/esa.c	21 Sep 2006 23:43:06 -0000
@@ -1136,7 +1136,8 @@
 		    audio_attach_mi(&esa_hw_if, &sc->voice[i], &sc->sc_dev);
 	}
 
-	sc->powerhook = powerhook_establish(esa_powerhook, sc);
+	sc->powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    esa_powerhook, sc);
 	if (sc->powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/esm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esm.c,v
retrieving revision 1.36
diff -u -r1.36 esm.c
--- sys/dev/pci/esm.c	30 Aug 2006 01:10:46 -0000	1.36
+++ sys/dev/pci/esm.c	21 Sep 2006 23:43:06 -0000
@@ -1700,7 +1700,8 @@
 	audio_attach_mi(&esm_hw_if, self, &ess->sc_dev);
 
 	ess->esm_suspend = PWR_RESUME;
-	ess->esm_powerhook = powerhook_establish(esm_powerhook, ess);
+	ess->esm_powerhook = powerhook_establish(ess->sc_dev.dv_xname,
+	    esm_powerhook, ess);
 }
 
 /* Power Hook */
Index: sys/dev/pci/if_ath_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_ath_pci.c,v
retrieving revision 1.16
diff -u -r1.16 if_ath_pci.c
--- sys/dev/pci/if_ath_pci.c	1 Aug 2006 18:11:32 -0000	1.16
+++ sys/dev/pci/if_ath_pci.c	21 Sep 2006 23:43:06 -0000
@@ -226,7 +226,8 @@
 		goto bad3;
 	}
 
-	phook = powerhook_establish(ath_pci_powerhook, psc);
+	phook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ath_pci_powerhook, psc);
 	if (phook == NULL) {
 		aprint_error("couldn't make power hook\n");
 		goto bad3;
Index: sys/dev/pci/if_bge.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_bge.c,v
retrieving revision 1.109
diff -u -r1.109 if_bge.c
--- sys/dev/pci/if_bge.c	1 Jun 2006 02:20:54 -0000	1.109
+++ sys/dev/pci/if_bge.c	21 Sep 2006 23:43:07 -0000
@@ -2659,7 +2659,8 @@
 	DPRINTFN(5, ("callout_init\n"));
 	callout_init(&sc->bge_timeout);
 
-	sc->bge_powerhook = powerhook_establish(bge_powerhook, sc);
+	sc->bge_powerhook = powerhook_establish(sc->bge_dev.dv_xname,
+	    bge_powerhook, sc);
 	if (sc->bge_powerhook == NULL)
 		printf("%s: WARNING: unable to establish PCI power hook\n",
 		    sc->bge_dev.dv_xname);
Index: sys/dev/pci/if_fxp_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_fxp_pci.c,v
retrieving revision 1.47
diff -u -r1.47 if_fxp_pci.c
--- sys/dev/pci/if_fxp_pci.c	30 Jul 2006 21:09:00 -0000	1.47
+++ sys/dev/pci/if_fxp_pci.c	21 Sep 2006 23:43:08 -0000
@@ -505,7 +505,8 @@
 		fxp_disable(sc);
 
 	/* Add a suspend hook to restore PCI config state */
-	psc->psc_powerhook = powerhook_establish(fxp_pci_powerhook, psc);
+	psc->psc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    fxp_pci_powerhook, psc);
 	if (psc->psc_powerhook == NULL)
 		aprint_error(
 		    "%s: WARNING: unable to establish pci power hook\n",
Index: sys/dev/pci/if_ipw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_ipw.c,v
retrieving revision 1.27
diff -u -r1.27 if_ipw.c
--- sys/dev/pci/if_ipw.c	2 Aug 2006 13:58:39 -0000	1.27
+++ sys/dev/pci/if_ipw.c	21 Sep 2006 23:43:08 -0000
@@ -346,7 +346,8 @@
 	if (sc->sc_sdhook == NULL)
 		aprint_error("%s: WARNING: unable to establish shutdown hook\n",
 		    sc->sc_dev.dv_xname);
-	sc->sc_powerhook = powerhook_establish(ipw_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    ipw_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/if_iwi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_iwi.c,v
retrieving revision 1.55
diff -u -r1.55 if_iwi.c
--- sys/dev/pci/if_iwi.c	30 Aug 2006 16:43:56 -0000	1.55
+++ sys/dev/pci/if_iwi.c	21 Sep 2006 23:43:09 -0000
@@ -465,7 +465,8 @@
 	if (sc->sc_sdhook == NULL)
 		aprint_error("%s: WARNING: unable to establish shutdown hook\n",
 		    sc->sc_dev.dv_xname);
-	sc->sc_powerhook = powerhook_establish(iwi_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    iwi_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/if_nfe.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_nfe.c,v
retrieving revision 1.4
diff -u -r1.4 if_nfe.c
--- sys/dev/pci/if_nfe.c	3 Sep 2006 07:42:04 -0000	1.4
+++ sys/dev/pci/if_nfe.c	21 Sep 2006 23:43:10 -0000
@@ -342,7 +342,8 @@
 	callout_init(&sc->sc_tick_ch);
 	callout_setfunc(&sc->sc_tick_ch, nfe_tick, sc);
 
-	sc->sc_powerhook = powerhook_establish(nfe_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    nfe_power, sc);
 }
 
 void
Index: sys/dev/pci/if_rtk_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_rtk_pci.c,v
retrieving revision 1.25
diff -u -r1.25 if_rtk_pci.c
--- sys/dev/pci/if_rtk_pci.c	1 Sep 2006 20:28:14 -0000	1.25
+++ sys/dev/pci/if_rtk_pci.c	21 Sep 2006 23:43:10 -0000
@@ -248,7 +248,8 @@
 	sc->sc_dmat = pa->pa_dmat;
 	sc->sc_flags |= RTK_ENABLED;
 
-	psc->sc_powerhook = powerhook_establish(rtk_pci_powerhook, psc);
+	psc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    rtk_pci_powerhook, psc);
 	if (psc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish pci power hook\n",
 			sc->sc_dev.dv_xname);
Index: sys/dev/pci/if_wi_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_wi_pci.c,v
retrieving revision 1.38
diff -u -r1.38 if_wi_pci.c
--- sys/dev/pci/if_wi_pci.c	11 Dec 2005 12:22:50 -0000	1.38
+++ sys/dev/pci/if_wi_pci.c	21 Sep 2006 23:43:10 -0000
@@ -383,7 +383,8 @@
 		sc->sc_reset = wi_pci_reset;
 
 	/* Add a suspend hook to restore PCI config state */
-	psc->sc_powerhook = powerhook_establish(wi_pci_powerhook, psc);
+	psc->sc_powerhook = powerhook_establish(self->dv_xname,
+	    wi_pci_powerhook, psc);
 	if (psc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish pci power hook\n",
 		    self->dv_xname);
Index: sys/dev/pci/if_wm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_wm.c,v
retrieving revision 1.124
diff -u -r1.124 if_wm.c
--- sys/dev/pci/if_wm.c	5 Jul 2006 23:51:50 -0000	1.124
+++ sys/dev/pci/if_wm.c	21 Sep 2006 23:43:11 -0000
@@ -1434,7 +1434,8 @@
 		aprint_error("%s: WARNING: unable to establish shutdown hook\n",
 		    sc->sc_dev.dv_xname);
 
-	sc->sc_powerhook = powerhook_establish(wm_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    wm_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: can't establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/if_wpi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_wpi.c,v
retrieving revision 1.2
diff -u -r1.2 if_wpi.c
--- sys/dev/pci/if_wpi.c	13 Aug 2006 03:52:33 -0000	1.2
+++ sys/dev/pci/if_wpi.c	21 Sep 2006 23:43:12 -0000
@@ -364,7 +364,7 @@
 	ieee80211_media_init(ic, wpi_media_change, ieee80211_media_status);
 
 	/* set powerhook */
-	sc->powerhook = powerhook_establish(wpi_power, sc);
+	sc->powerhook = powerhook_establish(sc->sc_dev.dv_xname, wpi_power, sc);
 
 #if NBPFILTER > 0
 	bpfattach2(ifp, DLT_IEEE802_11_RADIO,
Index: sys/dev/pci/neo.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/neo.c,v
retrieving revision 1.32
diff -u -r1.32 neo.c
--- sys/dev/pci/neo.c	2 Sep 2006 07:23:53 -0000	1.32
+++ sys/dev/pci/neo.c	21 Sep 2006 23:43:12 -0000
@@ -633,7 +633,7 @@
 	if (ac97_attach(&sc->host_if, self) != 0)
 		return;
 
-	sc->powerhook = powerhook_establish(neo_power, sc);
+	sc->powerhook = powerhook_establish(sc->dev.dv_xname, neo_power, sc);
 
 	audio_attach_mi(&neo_hw_if, sc, &sc->dev);
 }
Index: sys/dev/pci/pccbb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pccbb.c,v
retrieving revision 1.133
diff -u -r1.133 pccbb.c
--- sys/dev/pci/pccbb.c	8 Jul 2006 23:02:55 -0000	1.133
+++ sys/dev/pci/pccbb.c	21 Sep 2006 23:43:13 -0000
@@ -680,7 +680,7 @@
 	}
 
 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
-	powerhook_establish(pccbb_powerhook, sc);
+	powerhook_establish(sc->sc_dev.dv_xname, pccbb_powerhook, sc);
 
 	{
 		u_int32_t sockstat;
Index: sys/dev/pci/piixide.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/piixide.c,v
retrieving revision 1.29
diff -u -r1.29 piixide.c
--- sys/dev/pci/piixide.c	3 Sep 2006 18:30:35 -0000	1.29
+++ sys/dev/pci/piixide.c	21 Sep 2006 23:43:13 -0000
@@ -261,7 +261,8 @@
 	    pciide_lookup_product(pa->pa_id, pciide_intel_products));
 
 	/* Setup our powerhook */
-	sc->sc_powerhook = powerhook_establish(piixide_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(
+	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, piixide_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish PCI power hook\n",
 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
Index: sys/dev/pci/piixpm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/piixpm.c,v
retrieving revision 1.7
diff -u -r1.7 piixpm.c
--- sys/dev/pci/piixpm.c	17 Aug 2006 17:11:28 -0000	1.7
+++ sys/dev/pci/piixpm.c	21 Sep 2006 23:43:14 -0000
@@ -139,7 +139,8 @@
 	aprint_naive("\n");
 	aprint_normal(": Power Management Controller\n");
 
-	sc->sc_powerhook = powerhook_establish(piixpm_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    piixpm_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: can't establish powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pci/uhci_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/uhci_pci.c,v
retrieving revision 1.31
diff -u -r1.31 uhci_pci.c
--- sys/dev/pci/uhci_pci.c	10 Mar 2006 17:21:20 -0000	1.31
+++ sys/dev/pci/uhci_pci.c	21 Sep 2006 23:43:14 -0000
@@ -180,7 +180,8 @@
 	usb_pci_add(&sc->sc_pci, pa, &sc->sc.sc_bus);
 #endif
 
-	sc->sc_powerhook = powerhook_establish(uhci_pci_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(USBDEVNAME(sc->sc.sc_bus.bdev),
+	    uhci_pci_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: couldn't establish powerhook\n",
 		    devname);
Index: sys/dev/pci/yds.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/yds.c,v
retrieving revision 1.34
diff -u -r1.34 yds.c
--- sys/dev/pci/yds.c	3 Sep 2006 21:45:28 -0000	1.34
+++ sys/dev/pci/yds.c	21 Sep 2006 23:43:14 -0000
@@ -928,7 +928,7 @@
 	sc->sc_legacy_iot = pa->pa_iot;
 	config_defer((struct device*) sc, yds_configure_legacy);
 
-	powerhook_establish(yds_powerhook, sc);
+	powerhook_establish(sc->sc_dev.dv_xname, yds_powerhook, sc);
 }
 
 static int
Index: sys/dev/pckbport/pckbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/pckbd.c,v
retrieving revision 1.11
diff -u -r1.11 pckbd.c
--- sys/dev/pckbport/pckbd.c	18 Jun 2006 02:25:18 -0000	1.11
+++ sys/dev/pckbport/pckbd.c	21 Sep 2006 23:43:14 -0000
@@ -403,7 +403,8 @@
 	a.accessops = &pckbd_accessops;
 	a.accesscookie = sc;
 
-	sc->sc_powerhook = powerhook_establish(pckbd_powerhook, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    pckbd_powerhook, sc);
 	if (sc->sc_powerhook == NULL)
 		aprint_error("%s: unable to install powerhook\n",
 		    sc->sc_dev.dv_xname);
Index: sys/dev/pckbport/pms.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/pms.c,v
retrieving revision 1.11
diff -u -r1.11 pms.c
--- sys/dev/pckbport/pms.c	7 Jun 2006 22:33:37 -0000	1.11
+++ sys/dev/pckbport/pms.c	21 Sep 2006 23:43:14 -0000
@@ -228,7 +228,7 @@
 	kthread_create(pms_spawn_reset_thread, sc);
 
 #ifndef PMS_DISABLE_POWERHOOK
-	sc->sc_powerhook = powerhook_establish(pms_power, sc);
+	sc->sc_powerhook = powerhook_establish(self->dv_xname, pms_power, sc);
 	sc->sc_suspended = 0;
 #endif /* !PMS_DISABLE_POWERHOOK */
 }
Index: sys/dev/pcmcia/bt3c.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/bt3c.c,v
retrieving revision 1.3
diff -u -r1.3 bt3c.c
--- sys/dev/pcmcia/bt3c.c	28 Aug 2006 10:34:33 -0000	1.3
+++ sys/dev/pcmcia/bt3c.c	21 Sep 2006 23:43:15 -0000
@@ -883,7 +883,8 @@
 	hci_attach(&sc->sc_unit);
 
 	/* establish a power change hook */
-	sc->sc_powerhook = powerhook_establish(bt3c_power, sc);
+	sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
+	    bt3c_power, sc);
 	return;
 
 iomap_failed:
Index: sys/dev/pcmcia/if_an_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_an_pcmcia.c,v
retrieving revision 1.28
diff -u -r1.28 if_an_pcmcia.c
--- sys/dev/pcmcia/if_an_pcmcia.c	11 Dec 2005 12:23:23 -0000	1.28
+++ sys/dev/pcmcia/if_an_pcmcia.c	21 Sep 2006 23:43:15 -0000
@@ -167,7 +167,7 @@
 		goto fail2;
 	}
 
-	psc->sc_powerhook = powerhook_establish(an_power, sc);
+	psc->sc_powerhook = powerhook_establish(self->dv_xname, an_power, sc);
 
 	an_pcmcia_disable(sc);
 	sc->sc_enabled = 0;
Index: sys/dev/pcmcia/if_ep_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_ep_pcmcia.c,v
retrieving revision 1.55
diff -u -r1.55 if_ep_pcmcia.c
--- sys/dev/pcmcia/if_ep_pcmcia.c	11 Jul 2006 22:49:47 -0000	1.55
+++ sys/dev/pcmcia/if_ep_pcmcia.c	21 Sep 2006 23:43:15 -0000
@@ -339,7 +339,7 @@
 		aprint_error("%s: couldn't configure controller\n",
 		    self->dv_xname);
 
-	psc->sc_powerhook = powerhook_establish(ep_power, sc);
+	psc->sc_powerhook = powerhook_establish(self->dv_xname, ep_power, sc);
 	if (psc->sc_powerhook == NULL)
 		aprint_error("%s: WARNING: unable to establish power hook\n",
 		    self->dv_xname);
Index: sys/dev/pcmcia/if_ne_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_ne_pcmcia.c,v
retrieving revision 1.144
diff -u -r1.144 if_ne_pcmcia.c
--- sys/dev/pcmcia/if_ne_pcmcia.c	30 Aug 2006 16:55:06 -0000	1.144
+++ sys/dev/pcmcia/if_ne_pcmcia.c	21 Sep 2006 23:43:15 -0000
@@ -724,7 +724,8 @@
 	if (ne2000_attach(nsc, enaddr))
 		goto fail2;
 
-	psc->sc_powerhook = powerhook_establish(ne2000_power, nsc);
+	psc->sc_powerhook = powerhook_establish(self->dv_xname,
+	    ne2000_power, nsc);
 	if (psc->sc_powerhook == NULL)
 		printf("%s: WARNING: unable to establish power hook\n",
 		    self->dv_xname);
Index: sys/dev/pcmcia/if_ray.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_ray.c,v
retrieving revision 1.60
diff -u -r1.60 if_ray.c
--- sys/dev/pcmcia/if_ray.c	14 Apr 2006 17:50:27 -0000	1.60
+++ sys/dev/pcmcia/if_ray.c	21 Sep 2006 23:43:18 -0000
@@ -614,7 +614,7 @@
 		ifmedia_set(&sc->sc_media, IFM_INFRA);
 
 	sc->sc_sdhook = shutdownhook_establish(ray_shutdown, sc);
-	sc->sc_pwrhook = powerhook_establish(ray_power, sc);
+	sc->sc_pwrhook = powerhook_establish(self->dv_xname, ray_power, sc);
 
 	/* The attach is successful. */
 	sc->sc_attached = 1;
Index: sys/dev/pcmcia/if_wi_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_wi_pcmcia.c,v
retrieving revision 1.69
diff -u -r1.69 if_wi_pcmcia.c
--- sys/dev/pcmcia/if_wi_pcmcia.c	28 Jul 2006 08:02:39 -0000	1.69
+++ sys/dev/pcmcia/if_wi_pcmcia.c	21 Sep 2006 23:43:19 -0000
@@ -378,7 +378,8 @@
 	}
 
 	psc->sc_sdhook    = shutdownhook_establish(wi_pcmcia_shutdown, psc);
-	psc->sc_powerhook = powerhook_establish(wi_pcmcia_powerhook, psc);
+	psc->sc_powerhook = powerhook_establish(self->dv_xname,
+	    wi_pcmcia_powerhook, psc);
 
 	wi_pcmcia_disable(sc);
 	psc->sc_state = WI_PCMCIA_ATTACHED;
Index: sys/dev/sbus/dbri.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sbus/dbri.c,v
retrieving revision 1.5
diff -u -r1.5 dbri.c
--- sys/dev/sbus/dbri.c	28 May 2006 13:15:54 -0000	1.5
+++ sys/dev/sbus/dbri.c	21 Sep 2006 23:43:19 -0000
@@ -269,7 +269,7 @@
 		sc->sc_powerstate = 0;
 		printf("\n");
 		dbri_set_power(sc, 1);
-		powerhook_establish(dbri_powerhook, sc);
+		powerhook_establish(self->dv_xname, dbri_powerhook, sc);
 	} else {
 		/* we can't control power so we're always up */
 		sc->sc_have_powerctl = 0;
Index: sys/dev/sbus/p9100.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sbus/p9100.c,v
retrieving revision 1.33
diff -u -r1.33 p9100.c
--- sys/dev/sbus/p9100.c	28 May 2006 13:17:02 -0000	1.33
+++ sys/dev/sbus/p9100.c	21 Sep 2006 23:43:20 -0000
@@ -473,7 +473,7 @@
 	/* register with power management */
 	sc->sc_video = 1;
 	sc->sc_powerstate = PWR_RESUME;
-	powerhook_establish(p9100_power_hook, sc);
+	powerhook_establish(sc->sc_dev.dv_xname, p9100_power_hook, sc);
 
 #if NTCTRL > 0
 	/* register callback for external monitor status change */
Index: sys/dev/usb/ehci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ehci.c,v
retrieving revision 1.111
diff -u -r1.111 ehci.c
--- sys/dev/usb/ehci.c	30 Aug 2006 00:49:56 -0000	1.111
+++ sys/dev/usb/ehci.c	21 Sep 2006 23:43:21 -0000
@@ -417,7 +417,8 @@
 	sc->sc_bus.methods = &ehci_bus_methods;
 	sc->sc_bus.pipe_size = sizeof(struct ehci_pipe);
 
-	sc->sc_powerhook = powerhook_establish(ehci_power, sc);
+	sc->sc_powerhook = powerhook_establish(USBDEVNAME(sc->sc_bus.bdev),
+	    ehci_power, sc);
 	sc->sc_shutdownhook = shutdownhook_establish(ehci_shutdown, sc);
 
 	sc->sc_eintrs = EHCI_NORMAL_INTRS;
Index: sys/dev/usb/ohci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ohci.c,v
retrieving revision 1.175
diff -u -r1.175 ohci.c
--- sys/dev/usb/ohci.c	3 Sep 2006 07:06:39 -0000	1.175
+++ sys/dev/usb/ohci.c	21 Sep 2006 23:43:22 -0000
@@ -904,7 +904,8 @@
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 	sc->sc_control = sc->sc_intre = 0;
-	sc->sc_powerhook = powerhook_establish(ohci_power, sc);
+	sc->sc_powerhook = powerhook_establish(USBDEVNAME(sc->sc_bus.bdev),
+	    ohci_power, sc);
 	sc->sc_shutdownhook = shutdownhook_establish(ohci_shutdown, sc);
 #endif
 
Index: sys/dev/usb/uhci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uhci.c,v
retrieving revision 1.199
diff -u -r1.199 uhci.c
--- sys/dev/usb/uhci.c	3 Sep 2006 21:08:43 -0000	1.199
+++ sys/dev/usb/uhci.c	21 Sep 2006 23:43:22 -0000
@@ -547,7 +547,8 @@
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 	sc->sc_suspend = PWR_RESUME;
-	sc->sc_powerhook = powerhook_establish(uhci_power, sc);
+	sc->sc_powerhook = powerhook_establish(USBDEVNAME(sc->sc_bus.bdev),
+	    uhci_power, sc);
 	sc->sc_shutdownhook = shutdownhook_establish(uhci_shutdown, sc);
 #endif
 
Index: sys/conf/files
===================================================================
RCS file: /cvsroot/src/sys/conf/files,v
retrieving revision 1.810
diff -u -r1.810 files
--- sys/conf/files	7 Sep 2006 14:22:07 -0000	1.810
+++ sys/conf/files	21 Sep 2006 23:43:23 -0000
@@ -62,6 +62,7 @@
 defflag	opt_malloc_debug.h	MALLOC_DEBUG
 defflag	opt_pool.h		POOL_DIAGNOSTIC
 defparam opt_poollog.h		POOL_LOGSIZE
+defflag opt_powerhook.h		POWERHOOK_DEBUG
 
 defflag	opt_revcache.h		NAMECACHE_ENTER_REVERSE
 
Index: sys/kern/kern_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_subr.c,v
retrieving revision 1.143
diff -u -r1.143 kern_subr.c
--- sys/kern/kern_subr.c	2 Sep 2006 06:30:53 -0000	1.143
+++ sys/kern/kern_subr.c	21 Sep 2006 23:43:24 -0000
@@ -94,6 +94,7 @@
 #include "opt_ktrace.h"
 #include "opt_ptrace.h"
 #include "opt_systrace.h"
+#include "opt_powerhook.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -672,13 +673,14 @@
 	CIRCLEQ_ENTRY(powerhook_desc) sfd_list;
 	void	(*sfd_fn)(int, void *);
 	void	*sfd_arg;
+	char	sfd_name[16];
 };
 
 static CIRCLEQ_HEAD(, powerhook_desc) powerhook_list =
     CIRCLEQ_HEAD_INITIALIZER(powerhook_list);
 
 void *
-powerhook_establish(void (*fn)(int, void *), void *arg)
+powerhook_establish(char *name, void (*fn)(int, void *), void *arg)
 {
 	struct powerhook_desc *ndp;
 
@@ -689,6 +691,7 @@
 
 	ndp->sfd_fn = fn;
 	ndp->sfd_arg = arg;
+	strlcpy(ndp->sfd_name, name, sizeof(ndp->sfd_name));
 	CIRCLEQ_INSERT_HEAD(&powerhook_list, ndp, sfd_list);
 
 	return (ndp);
@@ -720,15 +723,47 @@
 {
 	struct powerhook_desc *dp;
 
+#ifdef POWERHOOK_DEBUG
+	printf("dopowerhooks ");
+	switch (why) {
+	case PWR_RESUME:
+		printf("resume");
+		break;
+	case PWR_SOFTRESUME:
+		printf("softresume");
+		break;
+	case PWR_SUSPEND:
+		printf("suspend");
+		break;
+	case PWR_SOFTSUSPEND:
+		printf("softsuspend");
+		break;
+	case PWR_STANDBY:
+		printf("standby");
+		break;
+	}
+	printf(":");
+#endif
+
 	if (why == PWR_RESUME || why == PWR_SOFTRESUME) {
 		CIRCLEQ_FOREACH_REVERSE(dp, &powerhook_list, sfd_list) {
+#ifdef POWERHOOK_DEBUG
+			printf(" %s", dp->sfd_name);
+#endif
 			(*dp->sfd_fn)(why, dp->sfd_arg);
 		}
 	} else {
 		CIRCLEQ_FOREACH(dp, &powerhook_list, sfd_list) {
+#ifdef POWERHOOK_DEBUG
+			printf(" %s", dp->sfd_name);
+#endif
 			(*dp->sfd_fn)(why, dp->sfd_arg);
 		}
 	}
+
+#ifdef POWERHOOK_DEBUG
+	printf(".\n");
+#endif
 }
 
 /*

--Apple-Mail-5-186608979--