Subject: merge of freebsd eventhandler
To: None <tech-kern@netbsd.org>
From: Brett Lymn <blymn@baesystems.com.au>
List: tech-kern
Date: 05/25/2006 22:13:45
--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Folks,

Attached is a diff and a couple of files that are an import of the
FreeBSD eventhandler code with some extra extensions to suit NetBSD.
Functionally, the eventhandler will work the same as it does in
FreeBSD but I have added the following:

1) An option to make an event run only once, the eventhandler list
   entries are marked as dead just prior to being run and will be
   removed from the eventhandler list at the end of the run.  This
   behaviour can be enabled by setting a flag on the eventhandler list
   (EHL_ONCE).

2) Provide a mask function - a masking function can be associated with
   a eventhandler list, this function takes the argument pointer that
   will be given to the functions on the eventhandler list, if the
   mask function returns 1 the eventhandler list function will be
   executed, otherwise the function will be skipped.

3) Provide a reverse traversal of the eventhandler list, this
   functions in exactly the same manner as forward traversal apart
   from the order that the eventhanlder list members are executed.

4) Provide fast versions of both forward and reverse traversals, the
   fast versions do not check for dead entries, prune the list of dead
   entries, perform any masking nor can they be made one shot lists.
   These are intended to be used where performance is important and
   the eventhandler list just needs to be run.

I have modified kern_subr to remove the function specific hook code
and use the eventhandler lists instead, most of the diff is modifying
the hook functions to reorder their arguments into a standard order.

The code builds and runs on a i386 machine, I have run a modified
kernel on my laptop with no apparent bad effects.  I would like to
commit this code to the tree in the near future.

Two things I need to do: 1) fix the file headers to include a NetBSD
copyright in addition to the original one, 2) grab the man page and
add in the extensions.

Below are the diffs (eventq.diff), eventhandler.h (goes in sys/sys)
and subr_eventhandler.c (goes in sys/kern)

-- 
Brett Lymn

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="eventq.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	25 May 2006 11:25:50 -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 "void (*fn)(void *a, int why)" "void *arg"
 .Ft void
 .Fn powerhook_disestablish "void *cookie"
 .Sh DESCRIPTION
@@ -56,9 +56,9 @@
 at power change.
 When invoked, the hook function
 .Fa fn
-will be passed the new power state as the first argument and
+will be passed 
 .Fa arg
-as its second argument.
+as the first argument and the new power state as its second argument.
 .Pp
 The
 .Fn powerhook_disestablish
Index: sys/arch/acorn32/acorn32/hydra.c
===================================================================
RCS file: /cvsroot/src/sys/arch/acorn32/acorn32/hydra.c,v
retrieving revision 1.20
diff -u -r1.20 hydra.c
--- sys/arch/acorn32/acorn32/hydra.c	8 Dec 2005 22:41:44 -0000	1.20
+++ sys/arch/acorn32/acorn32/hydra.c	25 May 2006 11:25:50 -0000
@@ -14,7 +14,7 @@
  *    documentation and/or other materials provided with the distribution.
  * 3. The name of the author may not be used to endorse or promote products
  *    derived from this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -135,7 +135,7 @@
 
 fail:
 	bus_space_unmap(iot, ioh, HYDRA_PHYS_SIZE);
-	return 0;	
+	return 0;
 }
 
 static void
@@ -367,7 +367,7 @@
 
 	cpu_setup(boot_args);
 	cpu_attach(curcpu()->ci_dev);
-	for (;;) { 
+	for (;;) {
 		bus_space_write_1(iot, ioh,
 		    HYDRA_HALT_SET, 1 << (cpunum & 3));
 		printf("%s: I am needed?\n", curcpu()->ci_dev->dv_xname);
@@ -381,7 +381,7 @@
 	struct hydra_softc *sc = the_hydra;
 	bus_space_tag_t iot = sc->sc_iot;
 	bus_space_handle_t ioh = sc->sc_ioh;
-	
+
 	bus_space_write_1(iot, ioh, HYDRA_HALT_CLR, 0xf);
 }
 
Index: sys/arch/hpcarm/dev/sed_saip.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcarm/dev/sed_saip.c,v
retrieving revision 1.18
diff -u -r1.18 sed_saip.c
--- sys/arch/hpcarm/dev/sed_saip.c	4 Mar 2006 16:51:56 -0000	1.18
+++ sys/arch/hpcarm/dev/sed_saip.c	25 May 2006 11:25:53 -0000
@@ -76,7 +76,7 @@
 static paddr_t	sed1356_mmap(void *, off_t, int);
 
 static int	sed1356_init(struct hpcfb_fbconf *);
-static void	sed1356_power(int, void *);
+static void	sed1356_power(void *, int);
 static void	sed1356_update_powerstate(struct sed1356_softc *, int);
 static void	sed1356_init_backlight(struct sed1356_softc *, int);
 static void	sed1356_set_brightness(struct sed1356_softc *, int);
@@ -149,7 +149,7 @@
 		printf(", console");
 	}
 	printf("\n");
-	printf("%s: framebuffer address: 0x%08lx\n", 
+	printf("%s: framebuffer address: 0x%08lx\n",
 	    sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
 
 	/* Add a suspend hook to power saving */
@@ -303,8 +303,8 @@
 	return 0; /* no error */
 }
 
-static void 
-sed1356_power(int why, void *arg)
+static void
+sed1356_power(void *arg, int why)
 {
 	struct sed1356_softc *sc = arg;
 
@@ -327,13 +327,13 @@
 	if (updates & PWRSTAT_LCD)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCD,
-		    (void *)!(sc->sc_powerstate & 
+		    (void *)!(sc->sc_powerstate &
 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
 
 	if (updates & PWRSTAT_BACKLIGHT)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
-		    (void *)(!(sc->sc_powerstate & 
+		    (void *)(!(sc->sc_powerstate &
 				(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
 			     (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
 }
@@ -353,7 +353,7 @@
 		 * XXX should be able to handle color map in 4/8 bpp mode.
 		 */
 		return EINVAL;
-	
+
 	case WSDISPLAYIO_SVIDEO:
 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
@@ -363,7 +363,7 @@
 		return 0;
 
 	case WSDISPLAYIO_GVIDEO:
-		*(int *)data = (sc->sc_powerstate & PWRSTAT_VIDEOOFF) ? 
+		*(int *)data = (sc->sc_powerstate & PWRSTAT_VIDEOOFF) ?
 				WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
 		return 0;
 
@@ -416,7 +416,7 @@
 				    " current=%d\n", sc->sc_max_brightness,
 				    sc->sc_brightness));
 				return 0;
-			}	
+			}
 			VPRINTF(("sed1356_ioctl: GET:BRIGHTNESS EINVAL\n"));
 			return EINVAL;
 
@@ -474,7 +474,7 @@
 #ifdef SED_DEBUG
 				int org = sc->sc_contrast;
 #endif
-				sed1356_set_contrast(sc, dispparam->curval);	
+				sed1356_set_contrast(sc, dispparam->curval);
 				VPRINTF(("sed1356_ioctl: SET:CONTRAST org=%d,"
 				    " current=%d\n", org, sc->sc_contrast));
 				return 0;
@@ -492,7 +492,7 @@
 #ifdef SED_DEBUG
 				int org = sc->sc_brightness;
 #endif
-				sed1356_set_brightness(sc, dispparam->curval);	
+				sed1356_set_brightness(sc, dispparam->curval);
 				VPRINTF(("sed1356_ioctl: SET:BRIGHTNESS org=%d,"
 				    " current=%d\n", org, sc->sc_brightness));
 				return 0;
@@ -588,7 +588,7 @@
 			sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real light state in attach time
 		   because light device not yet attached.
 		   we will retry in !inattach.
@@ -629,7 +629,7 @@
 		}
 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		 * we cannot get real brightness in attach time
 		 * because brightness device not yet attached.
 		 * we will retry in !inattach.
@@ -670,7 +670,7 @@
 		}
 		sc->sc_lcd_inited |= CONTRAST_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		 * we cannot get real contrast in attach time
 		 * because contrast device not yet attached.
 		 * we will retry in !inattach.
Index: sys/arch/hpcmips/dev/ite8181.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/dev/ite8181.c,v
retrieving revision 1.22
diff -u -r1.22 ite8181.c
--- sys/arch/hpcmips/dev/ite8181.c	11 Dec 2005 12:17:33 -0000	1.22
+++ sys/arch/hpcmips/dev/ite8181.c	25 May 2006 11:25:53 -0000
@@ -86,7 +86,7 @@
  * IBM WorkPad z50 power unit has too weak power.
  * So we must wait too many times to access some device
  * after LCD panel and BackLight on.
- * Currently delay is not enough ??? FIXME 
+ * Currently delay is not enough ??? FIXME
  */
 #ifndef ITE8181_LCD_ON_SELF_DELAY
 #define ITE8181_LCD_ON_SELF_DELAY 1000
@@ -117,7 +117,7 @@
 static void	ite8181_ema_write_1(struct ite8181_softc *, int, int);
 static int	ite8181_ema_read_1(struct ite8181_softc *, int);
 
-static void	ite8181_power(int, void *);
+static void	ite8181_power(void *, int);
 static int	ite8181_hardpower(void *, int, long, void *);
 static int	ite8181_fbinit(struct hpcfb_fbconf *);
 static int	ite8181_ioctl(void *, u_long, caddr_t, int, struct lwp *);
@@ -175,7 +175,7 @@
 ite8181_gui_read_1(struct ite8181_softc *sc, int byteoffset)
 {
 
-	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 
+	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh,
 	    sc->sc_gba + byteoffset));
 }
 
@@ -191,7 +191,7 @@
 ite8181_graphics_read_1(struct ite8181_softc *sc, int byteoffset)
 {
 
-	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 
+	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh,
 	    sc->sc_sba + byteoffset));
 }
 
@@ -218,7 +218,7 @@
 	ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
 	ite8181_graphics_write_1(sc, ITE8181_EMA_EXADATA, data);
 }
-	
+
 int
 ite8181_probe(bus_space_tag_t iot, bus_space_handle_t ioh)
 {
@@ -254,13 +254,13 @@
 	regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
 	printf("ITE8181 Rev.%02lx", regval & ITE8181_REV_MASK);
 	if (console) {
-		printf(", console");	
+		printf(", console");
 	}
 	printf("\n");
-	printf("%s: framebuffer address: 0x%08lx\n", 
+	printf("%s: framebuffer address: 0x%08lx\n",
 	    sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
 	if (ite8181_lcd_control_disable)
-		printf("%s: ite8181 lcd control is DISABLED.\n", 
+		printf("%s: ite8181 lcd control is DISABLED.\n",
 		    sc->sc_dev.dv_xname);
 
 	/* set base offsets */
@@ -335,7 +335,7 @@
 	}
 
 	if (sc->sc_lcd != on) {
-		ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA, 
+		ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
 		    ITE8181_EMA_ENABLEPASS);
 		lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
 		lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
@@ -355,7 +355,7 @@
 			 * IBM WorkPad z50 power unit has too weak power.
 			 * So we must wait too many times to access self device
 			 * after LCD panel and BackLight on.
-			 * Currently delay is not enough ??? FIXME 
+			 * Currently delay is not enough ??? FIXME
 			 */
 			delay(ite8181_lcd_on_self_delay*MSEC);
 			while (loop--) {
@@ -368,8 +368,8 @@
 				DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x,"
 				    " s=%x, seq=%x\n", on, loop, lcd_p, lcd_s,
 				    lcd_seq));
-				/* 
-				 *  XXX the states which are not described 
+				/*
+				 *  XXX the states which are not described
 				 *  XXX in manual.
 				 */
 				if (!(lcd_s&ITE8181_LCDPSTANDBY) &&
@@ -395,7 +395,7 @@
 				DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x,"
 				    " s=%x, seq=%x\n", on, loop, lcd_p, lcd_s,
 				    lcd_seq));
-				/* 
+				/*
 				 * XXX the states which are not described
 				 * XXX in manual.
 				 */
@@ -416,7 +416,7 @@
 		    ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ)));
 		ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
 		    ITE8181_EMA_DISABLEPASS);
-	}	
+	}
 	return 0;
 }
 
@@ -433,19 +433,19 @@
 	if (updates & PWRSTAT_LCD)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCD,
-		    (void*)!(sc->sc_powerstate & 
+		    (void*)!(sc->sc_powerstate &
 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
 
 	if (updates & PWRSTAT_BACKLIGHT)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
-		    (void*)(!(sc->sc_powerstate & 
+		    (void*)(!(sc->sc_powerstate &
 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
 			(sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
 }
 
-static void 
-ite8181_power(int why, void *arg)
+static void
+ite8181_power(void *arg, int why)
 {
         struct ite8181_softc *sc = arg;
 
@@ -477,19 +477,19 @@
 		delay(MSEC);
 		break;
 	case PWR_SUSPEND:
-		ite8181_lcd_power(sc, 0);	
+		ite8181_lcd_power(sc, 0);
 		delay(MSEC);
 		break;
 	case PWR_RESUME:
 		delay(MSEC);
-		ite8181_lcd_power(sc, 1);	
+		ite8181_lcd_power(sc, 1);
 		/*
 		 * XXX:
 		 * IBM WorkPad z50 power unit has too weak power.
 		 * So we must wait too many times to access other devices
 		 * after LCD panel and BackLight on.
 		 */
-		delay(ite8181_lcd_on_delay*MSEC);	
+		delay(ite8181_lcd_on_delay*MSEC);
 		break;
 	}
 
@@ -673,7 +673,7 @@
 		 * This driver can't set color map.
 		 */
 		return (EINVAL);
-	
+
 	case WSDISPLAYIO_SVIDEO:
 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
@@ -683,7 +683,7 @@
 		return 0;
 
 	case WSDISPLAYIO_GVIDEO:
-		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ? 
+		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
 		    WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
 		return 0;
 
@@ -700,7 +700,7 @@
 			dispparam->min = 0;
 			dispparam->max = 1;
 			if (sc->sc_max_brightness > 0)
-				dispparam->curval = 
+				dispparam->curval =
 				    sc->sc_brightness > 0 ? 1: 0;
 			else
 				dispparam->curval =
@@ -727,7 +727,7 @@
 				    "GET:CONTRAST EINVAL\n"));
 				return (EINVAL);
 			}
-			break;	
+			break;
 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
 			VPRINTF(("ite8181_ioctl: GET:BRIGHTNESS\n"));
 			ite8181_init_brightness(sc, 0);
@@ -909,7 +909,7 @@
 	if (sc->sc_lcd_inited&BACKLIGHT_INITED)
 		return;
 
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
 		/* we can get real light state */
 		VPRINTF(("ite8181_init_backlight: real backlight=%d\n", val));
@@ -919,7 +919,7 @@
 			sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real light state in attach time
 		   because light device not yet attached.
 		   we will retry in !inattach.
@@ -941,14 +941,14 @@
 		return;
 
 	VPRINTF(("ite8181_init_brightness\n"));
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
 		/* we can get real brightness max */
 		VPRINTF(("ite8181_init_brightness: real brightness max=%d\n",
 		    val));
 		sc->sc_max_brightness = val;
 		val = -1;
-		if (config_hook_call(CONFIG_HOOK_GET, 
+		if (config_hook_call(CONFIG_HOOK_GET,
 		    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
 			/* we can get real brightness */
 			VPRINTF(("ite8181_init_brightness:"
@@ -960,7 +960,7 @@
 		}
 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real brightness in attach time
 		   because brightness device not yet attached.
 		   we will retry in !inattach.
@@ -985,13 +985,13 @@
 		return;
 
 	VPRINTF(("ite8181_init_contrast\n"));
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
 		/* we can get real contrast max */
 		VPRINTF(("ite8181_init_contrast: real contrast max=%d\n", val));
 		sc->sc_max_contrast = val;
 		val = -1;
-		if (config_hook_call(CONFIG_HOOK_GET, 
+		if (config_hook_call(CONFIG_HOOK_GET,
 		    CONFIG_HOOK_CONTRAST, &val) != -1) {
 			/* we can get real contrast */
 			VPRINTF(("ite8181_init_contrast: real contrast=%d\n",
@@ -1002,7 +1002,7 @@
 		}
 		sc->sc_lcd_inited |= CONTRAST_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real contrast in attach time
 		   because contrast device not yet attached.
 		   we will retry in !inattach.
@@ -1025,7 +1025,7 @@
 	sc->sc_brightness = val;
 
 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
 		sc->sc_brightness = val;
 	}
@@ -1038,7 +1038,7 @@
 	sc->sc_contrast = val;
 
 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_CONTRAST, &val) != -1) {
 		sc->sc_contrast = val;
 	}
Index: sys/arch/hpcmips/dev/mq200.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/dev/mq200.c,v
retrieving revision 1.25
diff -u -r1.25 mq200.c
--- sys/arch/hpcmips/dev/mq200.c	11 Dec 2005 12:17:33 -0000	1.25
+++ sys/arch/hpcmips/dev/mq200.c	25 May 2006 11:25:53 -0000
@@ -56,13 +56,13 @@
 
 #include "bivideo.h"
 #if NBIVIDEO > 0
-#include <dev/hpc/bivideovar.h>     
+#include <dev/hpc/bivideovar.h>
 #endif
 
 /*
  * function prototypes
  */
-static void	mq200_power(int, void *);
+static void	mq200_power(void *, int);
 static int	mq200_hardpower(void *, int, long, void *);
 static int	mq200_fbinit(struct hpcfb_fbconf *);
 static int	mq200_ioctl(void *, u_long, caddr_t, int, struct lwp *);
@@ -196,7 +196,7 @@
 		mq200_dump_pll(sc);
 	}
 #endif
-	
+
 	/* Add a power hook to power saving */
 	sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
 	sc->sc_powerhook = powerhook_establish(mq200_power, sc);
@@ -250,19 +250,19 @@
 	if (updates & PWRSTAT_LCD)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCD,
-		    (void*)!(sc->sc_powerstate & 
+		    (void*)!(sc->sc_powerstate &
 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
 
 	if (updates & PWRSTAT_BACKLIGHT)
 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
-		    (void*)(!(sc->sc_powerstate & 
+		    (void*)(!(sc->sc_powerstate &
 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
 			(sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
 }
 
-static void 
-mq200_power(int why, void *arg)
+static void
+mq200_power(void *arg, int why)
 {
 	struct mq200_softc *sc = arg;
 
@@ -495,7 +495,7 @@
 		 * This driver can't set color map.
 		 */
 		return (EINVAL);
-	
+
 	case WSDISPLAYIO_SVIDEO:
 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
@@ -505,7 +505,7 @@
 		return 0;
 
 	case WSDISPLAYIO_GVIDEO:
-		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ? 
+		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
 		    WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
 		return 0;
 
@@ -547,7 +547,7 @@
 				VPRINTF("ioctl: GET:CONTRAST EINVAL\n");
 				return (EINVAL);
 			}
-			break;	
+			break;
 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
 			VPRINTF("ioctl: GET:BRIGHTNESS\n");
 			mq200_init_brightness(sc, 0);
@@ -726,7 +726,7 @@
 	if (sc->sc_lcd_inited&BACKLIGHT_INITED)
 		return;
 
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
 		/* we can get real light state */
 		VPRINTF("init_backlight: real backlight=%d\n", val);
@@ -736,7 +736,7 @@
 			sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real light state in attach time
 		   because light device not yet attached.
 		   we will retry in !inattach.
@@ -758,13 +758,13 @@
 		return;
 
 	VPRINTF("init_brightness\n");
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
 		/* we can get real brightness max */
 		VPRINTF("init_brightness: real brightness max=%d\n", val);
 		sc->sc_max_brightness = val;
 		val = -1;
-		if (config_hook_call(CONFIG_HOOK_GET, 
+		if (config_hook_call(CONFIG_HOOK_GET,
 		    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
 			/* we can get real brightness */
 			VPRINTF("init_brightness: real brightness=%d\n", val);
@@ -775,7 +775,7 @@
 		}
 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real brightness in attach time
 		   because brightness device not yet attached.
 		   we will retry in !inattach.
@@ -801,13 +801,13 @@
 		return;
 
 	VPRINTF("init_contrast\n");
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
 		/* we can get real contrast max */
 		VPRINTF("init_contrast: real contrast max=%d\n", val);
 		sc->sc_max_contrast = val;
 		val = -1;
-		if (config_hook_call(CONFIG_HOOK_GET, 
+		if (config_hook_call(CONFIG_HOOK_GET,
 		    CONFIG_HOOK_CONTRAST, &val) != -1) {
 			/* we can get real contrast */
 			VPRINTF("init_contrast: real contrast=%d\n", val);
@@ -817,7 +817,7 @@
 		}
 		sc->sc_lcd_inited |= CONTRAST_INITED;
 	} else if (inattach) {
-		/* 
+		/*
 		   we cannot get real contrast in attach time
 		   because contrast device not yet attached.
 		   we will retry in !inattach.
@@ -839,7 +839,7 @@
 	sc->sc_brightness = val;
 
 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
 		sc->sc_brightness = val;
 	}
@@ -851,7 +851,7 @@
 	sc->sc_contrast = val;
 
 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
-	if (config_hook_call(CONFIG_HOOK_GET, 
+	if (config_hook_call(CONFIG_HOOK_GET,
 	    CONFIG_HOOK_CONTRAST, &val) != -1) {
 		sc->sc_contrast = val;
 	}
Index: sys/arch/hpcmips/vr/vrpiu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/vr/vrpiu.c,v
retrieving revision 1.35
diff -u -r1.35 vrpiu.c
--- sys/arch/hpcmips/vr/vrpiu.c	11 Dec 2005 12:17:35 -0000	1.35
+++ sys/arch/hpcmips/vr/vrpiu.c	25 May 2006 11:25:53 -0000
@@ -123,7 +123,7 @@
 static void	vrpiu_start_powerstate(void *);
 static void	vrpiu_calc_powerstate(struct vrpiu_softc *);
 static void	vrpiu_send_battery_event(struct vrpiu_softc *);
-static void	vrpiu_power(int, void *);
+static void	vrpiu_power(void *, int);
 static u_int	scan_interval(u_int data);
 
 /* mra is defined in mra.c */
@@ -307,7 +307,7 @@
 #endif
 
 	/* install interrupt handler and enable interrupt */
-	if (!(sc->sc_handler = 
+	if (!(sc->sc_handler =
 	    vrip_intr_establish(sc->sc_vrip, sc->sc_unit, 0, IPL_TTY,
 		vrpiu_intr, sc))) {
 		printf (": can't map interrupt line.\n");
@@ -331,7 +331,7 @@
 	 * power management events
 	 */
 	sc->sc_power_hook = powerhook_establish(vrpiu_power, sc);
- 
+
 	/*
 	 * init A/D port polling.
 	 */
@@ -363,7 +363,7 @@
 	scale = WSMOUSE_RES_MAX - WSMOUSE_RES_MIN;
 	data += WSMOUSE_RES_MIN;
 
-	return PIUSIVL_SCANINTVAL_MIN + 
+	return PIUSIVL_SCANINTVAL_MIN +
 	    (PIUSIVL_SCANINTVAL_MAX - PIUSIVL_SCANINTVAL_MIN) *
 	    (scale - data) / scale;
 }
@@ -530,14 +530,14 @@
 			vrpiu_tp_disable(sc);
 		if (ad_enable)
 			vrpiu_ad_disable(sc);
-		
+
 		sc->sc_interval = scan_interval(*(u_int *)data);
 		DPRINTF(("%s(%d): WSMOUSEIO_SRES: *data=%d, interval=0x%03x\n",
 		    __FILE__, __LINE__, *(u_int *)data, sc->sc_interval));
-		
+
 		if (sc->sc_interval < PIUSIVL_SCANINTVAL_MIN)
 			sc->sc_interval = PIUSIVL_SCANINTVAL_MIN;
-			
+
 		if (PIUSIVL_SCANINTVAL_MAX < sc->sc_interval)
 			sc->sc_interval = PIUSIVL_SCANINTVAL_MAX;
 
@@ -688,7 +688,7 @@
 					xraw = tpy1 * sc->sc_pb_paddata_max / (tpy0 + tpy1);
 					yraw = tpx1 * sc->sc_pb_paddata_max / (tpx0 + tpx1);
 					DPRINTF(("%3d %3d", xraw, yraw));
-					
+
 					tpcalib_trans(&sc->sc_tpcalib, xraw,
 					    yraw, &x, &y);
 
@@ -820,11 +820,11 @@
 		    vrpiu_start_powerstate, sc);
 	if (bootverbose)
 		vrgiu_diff_io();
-		
+
 }
 
-static void 
-vrpiu_power(int why, void *arg)
+static void
+vrpiu_power(void *arg, int why)
 {
 	struct vrpiu_softc *sc = arg;
 
@@ -847,11 +847,11 @@
 	static int batterylow = 0;
 	static int critical = 0;
 
-	if (sc->sc_battery_spec == NULL 
+	if (sc->sc_battery_spec == NULL
 	    || sc->sc_battery_spec->main_port == -1)
 		return;
 
-	if (sc->sc_battery.value[sc->sc_battery_spec->main_port] 
+	if (sc->sc_battery.value[sc->sc_battery_spec->main_port]
 	    <= sc->sc_battery_spec->dc_critical) {
 		batteryhigh = 0;
 		config_hook_call(CONFIG_HOOK_PMEVENT,
@@ -866,7 +866,7 @@
 			batterylow = 0;
 		}
 		critical++;
-	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port] 
+	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port]
 	    <= sc->sc_battery_spec->dc_20p) {
 		batteryhigh = 0;
 		if (batterylow == 1)
@@ -877,7 +877,7 @@
 		    CONFIG_HOOK_PMEVENT_BATTERY,
 		    (void *)CONFIG_HOOK_BATT_LOW);
 		batterylow = 2;
-	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port] 
+	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port]
 	    <= sc->sc_battery_spec->dc_50p) {
 		batteryhigh = 0;
 		if (batterylow == 0) {
@@ -886,7 +886,7 @@
 			    CONFIG_HOOK_PMEVENT_BATTERY,
 			    (void *)CONFIG_HOOK_BATT_50P);
 		}
-	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port] 
+	} else if (sc->sc_battery.value[sc->sc_battery_spec->main_port]
 	    >= sc->sc_battery_spec->ac_80p) {
 		batterylow = 0;
 		if (batteryhigh == 0) {
@@ -898,7 +898,7 @@
 			    CONFIG_HOOK_PMEVENT_BATTERY,
 			    (void *)CONFIG_HOOK_BATT_HIGH);
 		}
-	} 
+	}
 #else /* VRPIU_ADHOC_BATTERY_EVENT */
 	config_hook_call(CONFIG_HOOK_SET,
 	    CONFIG_HOOK_BATTERYVAL,
Index: sys/arch/i386/bios/vesafb.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/bios/vesafb.c,v
retrieving revision 1.15
diff -u -r1.15 vesafb.c
--- sys/arch/i386/bios/vesafb.c	24 Apr 2006 14:14:38 -0000	1.15
+++ sys/arch/i386/bios/vesafb.c	25 May 2006 11:25:54 -0000
@@ -78,7 +78,7 @@
 					int, long *);
 
 static void	vesafb_init(struct vesafb_softc *);
-static void	vesafb_powerhook(int, void *);
+static void	vesafb_powerhook(void *, int);
 
 static int	vesafb_svideo(struct vesafb_softc *, u_int *);
 static int	vesafb_gvideo(struct vesafb_softc *, u_int *);
@@ -549,7 +549,7 @@
 }
 
 static void
-vesafb_powerhook(int why, void *opaque)
+vesafb_powerhook(void *opaque, int why)
 {
 #if notyet
 	struct vesafb_softc *sc;
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	25 May 2006 11:25:54 -0000
@@ -57,7 +57,7 @@
 void wi_obio_attach(struct device *, struct device *, void *);
 int wi_obio_enable(struct wi_softc *);
 void wi_obio_disable(struct wi_softc *);
-void wi_obio_powerhook(int, void *);
+void wi_obio_powerhook(void *, int);
 void wi_obio_shutdown(void *);
 
 struct wi_obio_softc {
@@ -179,9 +179,7 @@
 }
 
 void
-wi_obio_powerhook(why, arg)
-	int why;
-	void *arg;
+wi_obio_powerhook(void *arg, int why)
 {
 	struct wi_softc *sc = arg;
 
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.2
diff -u -r1.2 if_ae.c
--- sys/arch/mips/atheros/dev/if_ae.c	5 May 2006 18:04:41 -0000	1.2
+++ sys/arch/mips/atheros/dev/if_ae.c	25 May 2006 11:25:55 -0000
@@ -180,7 +180,7 @@
 
 static int	ae_enable(struct ae_softc *);
 static void	ae_disable(struct ae_softc *);
-static void	ae_power(int, void *);
+static void	ae_power(void *, int);
 
 static void	ae_filter_setup(struct ae_softc *);
 
@@ -1545,7 +1545,7 @@
  *	Power management (suspend/resume) hook.
  */
 static void
-ae_power(int why, void *arg)
+ae_power(void *arg, int why)
 {
 	struct ae_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
Index: sys/conf/files
===================================================================
RCS file: /cvsroot/src/sys/conf/files,v
retrieving revision 1.775
diff -u -r1.775 files
--- sys/conf/files	18 May 2006 09:05:51 -0000	1.775
+++ sys/conf/files	25 May 2006 11:25:58 -0000
@@ -1256,6 +1256,7 @@
 file	kern/subr_bufq.c
 file	kern/subr_devsw.c
 file	kern/subr_disk.c
+file	kern/subr_eventhandler.c
 file	kern/subr_iostat.c
 file	kern/subr_evcnt.c
 file	kern/subr_extent.c
Index: sys/dev/ata/ata.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/ata.c,v
retrieving revision 1.74
diff -u -r1.74 ata.c
--- sys/dev/ata/ata.c	29 Mar 2006 04:16:48 -0000	1.74
+++ sys/dev/ata/ata.c	25 May 2006 11:25:58 -0000
@@ -105,7 +105,7 @@
 
 extern struct cfdriver atabus_cd;
 
-static void atabus_powerhook(int, void *);
+static void atabus_powerhook(void *, int);
 
 /*
  * atabusprint:
@@ -1429,7 +1429,7 @@
 };
 
 static void
-atabus_powerhook(int why, void *hdl)
+atabus_powerhook(void *hdl, int why)
 {
 	struct atabus_softc *sc = (struct atabus_softc *)hdl;
 	struct ata_channel *chp = sc->sc_chan;
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	25 May 2006 11:25:59 -0000
@@ -104,7 +104,7 @@
 };
 
 static int bivideo_init(struct hpcfb_fbconf *);
-static void bivideo_power(int, void *);
+static void bivideo_power(void *, int);
 static void bivideo_update_powerstate(struct bivideo_softc *, int);
 void	bivideo_init_backlight(struct bivideo_softc *, int);
 void	bivideo_init_brightness(struct bivideo_softc *, int);
@@ -334,7 +334,7 @@
 }
 
 static void
-bivideo_power(int why, void *arg)
+bivideo_power(void *arg, int why)
 {
 	struct bivideo_softc *sc = arg;
 
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	25 May 2006 11:25:59 -0000
@@ -200,7 +200,7 @@
 static int	hpcfb_show_screen(void *, void *, int,
 		    void (*) (void *, int, int), void *);
 static void     hpcfb_pollc(void *, int);
-static void	hpcfb_power(int, void *);
+static void	hpcfb_power(void *, int);
 static void	hpcfb_cmap_reorder(struct hpcfb_fbconf *,
 		    struct hpcfb_devconfig *);
 
@@ -633,7 +633,7 @@
 }
 
 static void
-hpcfb_power(int why, void *arg)
+hpcfb_power(void *arg, int why)
 {
 	struct hpcfb_softc *sc = arg;
 
Index: sys/dev/ic/an.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/an.c,v
retrieving revision 1.43
diff -u -r1.43 an.c
--- sys/dev/ic/an.c	14 May 2006 21:42:27 -0000	1.43
+++ sys/dev/ic/an.c	25 May 2006 11:26:00 -0000
@@ -321,8 +321,8 @@
 
 	ieee80211_media_init(ic, an_media_change, an_media_status);
 
-	/* 
-	 * radiotap BPF device 
+	/*
+	 * radiotap BPF device
 	 */
 #if NBPFILTER > 0
 	bpfattach2(ifp, DLT_IEEE802_11_RADIO,
@@ -449,7 +449,7 @@
 }
 
 void
-an_power(int why, void *arg)
+an_power(void *arg, int why)
 {
 	int s;
 	struct an_softc *sc = arg;
@@ -1514,7 +1514,7 @@
 		    (le16toh(frmhdr.an_rx_status) & AN_STAT_ERRSTAT) ||
 		    (le16toh(frmhdr.an_rx_status) & AN_STAT_UNDECRYPTABLE))
 		    tap->ar_flags |= IEEE80211_RADIOTAP_F_BADFCS;
-		
+
 		bpf_mtap2(sc->sc_drvbpf, tap, tap->ar_ihdr.it_len, m);
 	}
 #endif
Index: sys/dev/ic/anvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/anvar.h,v
retrieving revision 1.13
diff -u -r1.13 anvar.h
--- sys/dev/ic/anvar.h	19 Feb 2006 08:20:02 -0000	1.13
+++ sys/dev/ic/anvar.h	25 May 2006 11:26:00 -0000
@@ -165,7 +165,7 @@
 int	an_attach(struct an_softc *);
 int	an_detach(struct an_softc *);
 int	an_activate(struct device *, enum devact);
-void	an_power(int, void *);
+void	an_power(void *, int);
 void	an_shutdown(struct an_softc *);
 int	an_intr(void *);
 
Index: sys/dev/ic/ath.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/ath.c,v
retrieving revision 1.72
diff -u -r1.72 ath.c
--- sys/dev/ic/ath.c	11 May 2006 22:26:54 -0000	1.72
+++ sys/dev/ic/ath.c	25 May 2006 11:26:01 -0000
@@ -58,11 +58,11 @@
 #endif /* __NetBSD__ */
 
 #include <sys/param.h>
-#include <sys/reboot.h> 
-#include <sys/systm.h> 
+#include <sys/reboot.h>
+#include <sys/systm.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
-#include <sys/mbuf.h>   
+#include <sys/mbuf.h>
 #include <sys/malloc.h>
 #include <sys/lock.h>
 #include <sys/kernel.h>
@@ -74,7 +74,7 @@
 #include <sys/endian.h>
 
 #include <machine/bus.h>
- 
+
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_media.h>
@@ -91,7 +91,7 @@
 #endif
 
 #ifdef INET
-#include <netinet/in.h> 
+#include <netinet/in.h>
 #endif
 
 #include <sys/device.h>
@@ -196,7 +196,7 @@
 #ifdef __NetBSD__
 int	ath_enable(struct ath_softc *);
 void	ath_disable(struct ath_softc *);
-void	ath_power(int, void *);
+void	ath_power(void *, int);
 #endif
 
 #if NBPFILTER > 0
@@ -455,7 +455,7 @@
 	if (!ath_tx_setup(sc, WME_AC_BE, HAL_WME_AC_BE) ||
 	    !ath_tx_setup(sc, WME_AC_VI, HAL_WME_AC_VI) ||
 	    !ath_tx_setup(sc, WME_AC_VO, HAL_WME_AC_VO)) {
-		/* 
+		/*
 		 * Not enough hardware tx queues to properly do WME;
 		 * just punt and assign them all to the same h/w queue.
 		 * We could do a better job of this if, for example,
@@ -471,7 +471,7 @@
 		sc->sc_ac2q[WME_AC_VO] = sc->sc_ac2q[WME_AC_BK];
 	}
 
-	/* 
+	/*
 	 * Special case certain configurations.  Note the
 	 * CAB queue is handled by these specially so don't
 	 * include them when checking the txq setup mask.
@@ -683,7 +683,7 @@
 #if NBPFILTER > 0
 	bpfdetach(ifp);
 #endif
-	/* 
+	/*
 	 * NB: the order of these is important:
 	 * o call the 802.11 layer before detaching the hal to
 	 *   insure callbacks into the driver to delete global
@@ -715,7 +715,7 @@
 
 #ifdef __NetBSD__
 void
-ath_power(int why, void *arg)
+ath_power(void *arg, int why)
 {
 	struct ath_softc *sc = arg;
 	int s;
@@ -1275,7 +1275,7 @@
 				ATH_TXBUF_UNLOCK(sc);
 				break;
 			}
-			/* 
+			/*
 			 * Find the node for the destination so we can do
 			 * things like power save and fast frames aggregation.
 			 */
@@ -2393,7 +2393,7 @@
 		if (bs.bs_sleepduration > bs.bs_dtimperiod)
 			bs.bs_sleepduration = roundup(bs.bs_sleepduration, bs.bs_dtimperiod);
 
-		DPRINTF(sc, ATH_DEBUG_BEACON, 
+		DPRINTF(sc, ATH_DEBUG_BEACON,
 			"%s: tsf %ju tsf:tu %u intval %u nexttbtt %u dtim %u nextdtim %u bmiss %u sleep %u cfp:period %u maxdur %u next %u timoffset %u\n"
 			, __func__
 			, tsf, tsftu
@@ -2909,7 +2909,7 @@
 				bf->bf_daddr, PA2DESC(sc, ds->ds_link));
 #ifdef AR_DEBUG
 		if (sc->sc_debug & ATH_DEBUG_RECV_DESC)
-			ath_printrxbuf(bf, status == HAL_OK); 
+			ath_printrxbuf(bf, status == HAL_OK);
 #endif
 		if (status == HAL_EINPROGRESS)
 			break;
@@ -3234,7 +3234,7 @@
 	ath_hal_gettxqueueprops(ah, txq->axq_qnum, &qi);
 	qi.tqi_aifs = wmep->wmep_aifsn;
 	qi.tqi_cwmin = ATH_EXPONENT_TO_VALUE(wmep->wmep_logcwmin);
-	qi.tqi_cwmax = ATH_EXPONENT_TO_VALUE(wmep->wmep_logcwmax);	
+	qi.tqi_cwmax = ATH_EXPONENT_TO_VALUE(wmep->wmep_logcwmax);
 	qi.tqi_burstTime = ATH_TXOP_TO_US(wmep->wmep_txopLimit);
 
 	if (!ath_hal_settxqueueprops(ah, txq->axq_qnum, &qi)) {
@@ -3747,7 +3747,7 @@
 	}
 #endif
 
-	/* 
+	/*
 	 * Determine if a tx interrupt should be generated for
 	 * this descriptor.  We take a tx interrupt to reap
 	 * descriptors when the h/w hits an EOL condition or
@@ -4199,7 +4199,7 @@
 	return 0;
 }
 
-/* 
+/*
  * Update internal state after a channel change.
  */
 static void
@@ -4419,7 +4419,7 @@
 	ath_hal_process_noisefloor(ah);
 	/*
 	 * Poll more frequently when the IQ calibration is in
-	 * progress to speedup loading the final settings. 
+	 * progress to speedup loading the final settings.
 	 * We temper this aggressive polling with an exponential
 	 * back off after 4 tries up to ath_calinterval.
 	 */
@@ -4805,7 +4805,7 @@
 		(void)ath_hal_gettxpowlimit(ah, &txpow);
 		ic->ic_txpowlimit = sc->sc_curtxpow = txpow;
 	}
-	/* 
+	/*
 	 * Fetch max tx power level for status requests.
 	 */
 	(void)ath_hal_getmaxtxpow(sc->sc_ah, &txpow);
@@ -5130,7 +5130,7 @@
 	default:
 		error = ieee80211_ioctl(ic, cmd, data);
 		if (error == ENETRESET) {
-			if (IS_RUNNING(ifp) && 
+			if (IS_RUNNING(ifp) &&
 			    ic->ic_roaming != IEEE80211_ROAMING_MANUAL)
 				ath_init(sc);	/* XXX lose error */
 			error = 0;
Index: sys/dev/ic/athvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/athvar.h,v
retrieving revision 1.16
diff -u -r1.16 athvar.h
--- sys/dev/ic/athvar.h	2 Apr 2006 05:52:50 -0000	1.16
+++ sys/dev/ic/athvar.h	25 May 2006 11:26:01 -0000
@@ -264,7 +264,7 @@
 	u_int			sc_txqsetup;	/* h/w queues setup */
 	u_int			sc_txintrperiod;/* tx interrupt batching */
 	struct ath_txq		sc_txq[HAL_NUM_TX_QUEUES];
-	struct ath_txq		*sc_ac2q[5];	/* WME AC -> h/w q map */ 
+	struct ath_txq		*sc_ac2q[5];	/* WME AC -> h/w q map */
 	ath_task_t		sc_txtask;	/* tx int processing */
 
 	struct ath_descdma	sc_bdma;	/* beacon descriptors */
@@ -308,7 +308,7 @@
 void	ath_resume(struct ath_softc *, int);
 void	ath_suspend(struct ath_softc *, int);
 int	ath_activate(struct device *, enum devact);
-void	ath_power(int, void *);
+void	ath_power(void *, int);
 void	ath_shutdown(void *);
 int	ath_intr(void *);
 int	ath_reset(struct ifnet *);
Index: sys/dev/ic/atw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/atw.c,v
retrieving revision 1.117
diff -u -r1.117 atw.c
--- sys/dev/ic/atw.c	6 Apr 2006 06:08:26 -0000	1.117
+++ sys/dev/ic/atw.c	25 May 2006 11:26:02 -0000
@@ -211,7 +211,7 @@
 /* Device (de)activation and power state */
 void	atw_disable(struct atw_softc *);
 int	atw_enable(struct atw_softc *);
-void	atw_power(int, void *);
+void	atw_power(void *, int);
 void	atw_reset(struct atw_softc *);
 void	atw_shutdown(void *);
 
@@ -3803,7 +3803,7 @@
  *	Power management (suspend/resume) hook.
  */
 void
-atw_power(int why, void *arg)
+atw_power(void *arg, int why)
 {
 	struct atw_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_if;
Index: sys/dev/ic/atwvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/atwvar.h,v
retrieving revision 1.21
diff -u -r1.21 atwvar.h
--- sys/dev/ic/atwvar.h	8 Mar 2006 08:26:50 -0000	1.21
+++ sys/dev/ic/atwvar.h	25 May 2006 11:26:02 -0000
@@ -453,7 +453,7 @@
 int	atw_detach(struct atw_softc *);
 int	atw_activate(struct device *, enum devact);
 int	atw_intr(void *arg);
-void	atw_power(int, void *);
+void	atw_power(void *, int);
 void	atw_shutdown(void *);
 
 #endif /* _DEV_IC_ATWVAR_H_ */
Index: sys/dev/ic/awi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/awi.c,v
retrieving revision 1.70
diff -u -r1.70 awi.c
--- sys/dev/ic/awi.c	14 Apr 2006 20:33:57 -0000	1.70
+++ sys/dev/ic/awi.c	25 May 2006 11:26:03 -0000
@@ -417,7 +417,7 @@
 }
 
 void
-awi_power(int why, void *arg)
+awi_power(void *arg, int why)
 {
 	struct awi_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_if;
Index: sys/dev/ic/awivar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/awivar.h,v
retrieving revision 1.22
diff -u -r1.22 awivar.h
--- sys/dev/ic/awivar.h	11 Dec 2005 12:21:26 -0000	1.22
+++ sys/dev/ic/awivar.h	25 May 2006 11:26:03 -0000
@@ -154,7 +154,7 @@
 int	awi_detach(struct awi_softc *);
 #ifdef __NetBSD__
 int	awi_activate(struct device *, enum devact);
-void	awi_power(int, void *);
+void	awi_power(void *, int);
 #endif
 void	awi_shutdown(void *);
 int	awi_intr(void *);
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	25 May 2006 11:26:04 -0000
@@ -289,7 +289,7 @@
 static int cs_enable(struct cs_softc *);
 static void cs_disable(struct cs_softc *);
 static void cs_stop(struct ifnet *, int);
-static void cs_power(int, void *);
+static void cs_power(void *, int);
 static int cs_scan_eeprom(struct cs_softc *);
 static int cs_read_pktpg_from_eeprom(struct cs_softc *, int, u_int16_t *);
 
@@ -2219,7 +2219,7 @@
 }
 
 static void
-cs_power(int why, void *arg)
+cs_power(void *arg, int why)
 {
 	struct cs_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
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	25 May 2006 11:26:04 -0000
@@ -105,7 +105,7 @@
 void ex_printstats(struct ex_softc *);
 void ex_tick(void *);
 
-void ex_power(int, void *);
+void ex_power(void *, int);
 
 static int ex_eeprom_busy(struct ex_softc *);
 static int ex_add_rxbuf(struct ex_softc *, struct ex_rxdesc *);
@@ -1951,9 +1951,7 @@
 }
 
 void
-ex_power(why, arg)
-	int why;
-	void *arg;
+ex_power(void *arg, int why)
 {
 	struct ex_softc *sc = (void *)arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
Index: sys/dev/ic/gem.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/gem.c,v
retrieving revision 1.45
diff -u -r1.45 gem.c
--- sys/dev/ic/gem.c	2 Jan 2006 05:46:25 -0000	1.45
+++ sys/dev/ic/gem.c	25 May 2006 11:26:04 -0000
@@ -120,7 +120,7 @@
 int		gem_eint(struct gem_softc *, u_int);
 int		gem_rint(struct gem_softc *);
 int		gem_tint(struct gem_softc *);
-void		gem_power(int, void *);
+void		gem_power(void *, int);
 
 #ifdef GEM_DEBUG
 #define	DPRINTF(sc, x)	if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \
@@ -497,7 +497,7 @@
 {
 	int i;
 	u_int32_t reg;
-	
+
 	for (i = TRIES; i--; DELAY(100)) {
 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_h, r);
 		if ((r & clr) == 0 && (r & set) == set)
@@ -2181,9 +2181,7 @@
  *	Power management (suspend/resume) hook.
  */
 void
-gem_power(why, arg)
-	int why;
-	void *arg;
+gem_power(void *arg, int why)
 {
 	struct gem_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
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	25 May 2006 11:26:05 -0000
@@ -104,7 +104,7 @@
 void	pcic_event_thread(void *);
 
 void	pcic_queue_event(struct pcic_handle *, int);
-void	pcic_power(int, void *);
+void	pcic_power(void *, int);
 
 static int	pcic_wait_ready(struct pcic_handle *);
 static void	pcic_delay(struct pcic_handle *, int, const char *);
@@ -350,9 +350,7 @@
 }
 
 void
-pcic_power(why, arg)
-	int why;
-	void *arg;
+pcic_power(void *arg, int why)
 {
 	struct pcic_handle *h = (struct pcic_handle *)arg;
 	struct pcic_softc *sc = (struct pcic_softc *)h->ph_parent;
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	25 May 2006 11:26:05 -0000
@@ -208,7 +208,7 @@
 void	fxp_load_ucode(struct fxp_softc *);
 
 void	fxp_shutdown(void *);
-void	fxp_power(int, void *);
+void	fxp_power(void *, int);
 
 int	fxp_copy_small = 0;
 
@@ -557,7 +557,7 @@
  * clobber kernel memory at the wrong time.
  */
 void
-fxp_power(int why, void *arg)
+fxp_power(void *arg, int why)
 {
 	struct fxp_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
Index: sys/dev/ic/rtl8169.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl8169.c,v
retrieving revision 1.23
diff -u -r1.23 rtl8169.c
--- sys/dev/ic/rtl8169.c	16 May 2006 22:39:24 -0000	1.23
+++ sys/dev/ic/rtl8169.c	25 May 2006 11:26:06 -0000
@@ -170,7 +170,7 @@
 static void re_shutdown(void *);
 static int re_enable(struct rtk_softc *);
 static void re_disable(struct rtk_softc *);
-static void re_power(int, void *);
+static void re_power(void *, int);
 
 static int re_ifmedia_upd(struct ifnet *);
 static void re_ifmedia_sts(struct ifnet *, struct ifmediareq *);
@@ -983,7 +983,7 @@
  *     Power management (suspend/resume) hook.
  */
 void
-re_power(int why, void *arg)
+re_power(void *arg, int why)
 {
 	struct rtk_softc *sc = (void *) arg;
 	struct ifnet *ifp = &sc->ethercom.ec_if;
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	25 May 2006 11:26:06 -0000
@@ -157,7 +157,7 @@
 
 STATIC int rtk_enable		(struct rtk_softc *);
 STATIC void rtk_disable		(struct rtk_softc *);
-STATIC void rtk_power		(int, void *);
+STATIC void rtk_power		(void *, int);
 
 STATIC int rtk_list_tx_init(struct rtk_softc *);
 
@@ -942,9 +942,7 @@
  *     Power management (suspend/resume) hook.
  */
 void
-rtk_power(why, arg)
-	int why;
-	void *arg;
+rtk_power(void *arg, int why)
 {
 	struct rtk_softc *sc = (void *) arg;
 	struct ifnet *ifp = &sc->ethercom.ec_if;
Index: sys/dev/ic/rtw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtw.c,v
retrieving revision 1.73
diff -u -r1.73 rtw.c
--- sys/dev/ic/rtw.c	14 May 2006 05:42:43 -0000	1.73
+++ sys/dev/ic/rtw.c	25 May 2006 11:26:07 -0000
@@ -1777,7 +1777,7 @@
 		SIMPLEQ_REMOVE_HEAD(&tsb->tsb_dirtyq, ts_q);
 		SIMPLEQ_INSERT_TAIL(&tsb->tsb_freeq, ts, ts_q);
 	}
-	/* no more pending transmissions, cancel watchdog */ 
+	/* no more pending transmissions, cancel watchdog */
 	if (ts == NULL)
 		tsb->tsb_tx_timer = 0;
 	rtw_reset_oactive(sc);
@@ -3730,7 +3730,7 @@
 }
 
 void
-rtw_power(int why, void *arg)
+rtw_power(void *arg, int why)
 {
 	struct rtw_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_if;
Index: sys/dev/ic/rtwvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtwvar.h,v
retrieving revision 1.29
diff -u -r1.29 rtwvar.h
--- sys/dev/ic/rtwvar.h	14 May 2006 04:08:09 -0000	1.29
+++ sys/dev/ic/rtwvar.h	25 May 2006 11:26:07 -0000
@@ -504,7 +504,7 @@
 int rtw_enable(struct rtw_softc *);
 
 int rtw_activate(struct device *, enum devact);
-void rtw_power(int, void *);
+void rtw_power(void *, int);
 void rtw_shutdown(void *);
 
 const char *rtw_pwrstate_string(enum rtw_pwrstate);
Index: sys/dev/ic/tulip.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/tulip.c,v
retrieving revision 1.144
diff -u -r1.144 tulip.c
--- sys/dev/ic/tulip.c	14 May 2006 21:42:27 -0000	1.144
+++ sys/dev/ic/tulip.c	25 May 2006 11:26:09 -0000
@@ -110,7 +110,7 @@
 
 static int	tlp_enable(struct tulip_softc *);
 static void	tlp_disable(struct tulip_softc *);
-static void	tlp_power(int, void *);
+static void	tlp_power(void *, int);
 
 static void	tlp_filter_setup(struct tulip_softc *);
 static void	tlp_winb_filter_setup(struct tulip_softc *);
@@ -1696,7 +1696,7 @@
 		if (sc->sc_maxburst == 0)
 			sc->sc_maxburst = 16;
 		break;
-	
+
 	case TULIP_CHIP_AX88140:
 	case TULIP_CHIP_AX88141:
 		if (sc->sc_maxburst == 0)
@@ -1941,7 +1941,7 @@
 	    {
 		u_int32_t reg;
 		u_int8_t *enaddr = LLADDR(ifp->if_sadl);
-		    
+
 		reg = enaddr[0] |
 		      (enaddr[1] << 8) |
 		      (enaddr[2] << 16) |
@@ -2038,7 +2038,7 @@
  *	Power management (suspend/resume) hook.
  */
 static void
-tlp_power(int why, void *arg)
+tlp_power(void *arg, int why)
 {
 	struct tulip_softc *sc = arg;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
@@ -2998,7 +2998,7 @@
 
 /*
  * tlp_asix_filter_setup:
- * 
+ *
  * 	Set the ASIX AX8814x recieve filter.
  */
 static void
@@ -3041,7 +3041,7 @@
 			 */
 			goto allmulti;
 		}
-		hash = (ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26) 
+		hash = (ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26)
 		       & 0x3f;
 		if (hash < 32)
 			mchash[0] |= (1 << hash);
@@ -3613,7 +3613,7 @@
 
 /*
  * tlp_asix_preinit:
- * 
+ *
  * 	Pre-init function for the ASIX chipsets.
  */
 static void
@@ -3624,7 +3624,7 @@
 		case TULIP_CHIP_AX88140:
 		case TULIP_CHIP_AX88141:
 			/* XXX Handle PHY. */
-			sc->sc_opmode |= OPMODE_HBD|OPMODE_PS; 
+			sc->sc_opmode |= OPMODE_HBD|OPMODE_PS;
 			break;
 		default:
 			/* Nothing */
@@ -6173,7 +6173,7 @@
 	    MII_OFFSET_ANY, 0);
 
 	/* XXX Figure how to handle the PHY. */
-	
+
 	if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
 		ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
@@ -6183,13 +6183,13 @@
 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
 	}
 
-	
+
 }
 
 static void
 tlp_asix_tmsw_getmedia(struct tulip_softc *sc, struct ifmediareq *ifmr)
 {
-	
+
 	/* XXX PHY handling. */
 	tlp_mii_getmedia(sc, ifmr);
 }
@@ -6197,7 +6197,7 @@
 static int
 tlp_asix_tmsw_setmedia(struct tulip_softc *sc)
 {
-	
+
 	/* XXX PHY handling. */
 	return (tlp_mii_setmedia(sc));
 }
@@ -6248,4 +6248,3 @@
 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
 	}
 }
-
Index: sys/dev/ieee1394/fwohci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ieee1394/fwohci.c,v
retrieving revision 1.99
diff -u -r1.99 fwohci.c
--- sys/dev/ieee1394/fwohci.c	3 May 2006 00:37:44 -0000	1.99
+++ sys/dev/ieee1394/fwohci.c	25 May 2006 11:26:10 -0000
@@ -32,7 +32,7 @@
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- * 
+ *
  * $FreeBSD: /repoman/r/ncvs/src/sys/dev/firewire/fwohci.c,v 1.81 2005/03/29 01:44:59 sam Exp $
  *
  */
@@ -138,7 +138,7 @@
 
 	/* fwohci no cyclemaster flag */
 	if ((rc = sysctl_createv(clog, 0, NULL, &node,
-	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, 
+	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
 	    "nocyclemaster", SYSCTL_DESCR("Do not send cycle start packets"),
 	    NULL, 0, &nocyclemaster,
 	    0, CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL)) != 0) {
@@ -233,7 +233,7 @@
 static void fwohci_complete(void *, int);
 #endif
 #if defined(__NetBSD__)
-static void fwohci_power(int, void *);
+static void fwohci_power(void *, int);
 int fwohci_print(void *, const char *);
 #endif
 
@@ -423,7 +423,7 @@
 		}
 	}
 	if (firewire_debug || retry >= MAX_RETRY)
-		device_printf(sc->fc.dev, 
+		device_printf(sc->fc.dev,
 		    "fwphy_rddata: 0x%x loop=%d, retry=%d\n", addr, i, retry);
 #undef MAX_RETRY
 	return((fun >> PHYDEV_RDDATA )& 0xff);
@@ -500,7 +500,7 @@
 /*
  * probe PHY parameters
  * 0. to prove PHY version, whether compliance of 1394a.
- * 1. to probe maximum speed supported by the PHY and 
+ * 1. to probe maximum speed supported by the PHY and
  *    number of port supported by core-logic.
  *    It is not actually available port on your PC .
  */
@@ -576,7 +576,7 @@
 	uint32_t reg, reg2;
 	struct fwohcidb_tr *db_tr;
 
-	/* Disable interrupts */ 
+	/* Disable interrupts */
 	OWRITE(sc, FWOHCI_INTMASKCLR, ~0);
 
 	/* Now stopping all DMA channels */
@@ -667,8 +667,8 @@
 
 	/* Enable interrupts */
 	OWRITE(sc, FWOHCI_INTMASK,
-			OHCI_INT_ERR  | OHCI_INT_PHY_SID 
-			| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS 
+			OHCI_INT_ERR  | OHCI_INT_PHY_SID
+			| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
 			| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
 			| OHCI_INT_PHY_BUS_R | OHCI_INT_PW_ERR);
 	fwohci_set_intr(&sc->fc, 1);
@@ -890,7 +890,7 @@
 	int _cnt = _dbtr->dbcnt;					\
 	db = &_dbtr->db[ (_cnt > 2) ? (_cnt -1) : 0];			\
 } while (0)
-	
+
 static void
 fwohci_execute_db(void *arg, bus_dma_segment_t *segs, int nseg, int error)
 {
@@ -1037,7 +1037,7 @@
 					m_copydata(xfer->mbuf, 0,
 						xfer->mbuf->m_pkthdr.len,
 						mtod(m0, caddr_t));
-					m0->m_len = m0->m_pkthdr.len = 
+					m0->m_len = m0->m_pkthdr.len =
 						xfer->mbuf->m_pkthdr.len;
 					m_freem(xfer->mbuf);
 					xfer->mbuf = m0;
@@ -1375,7 +1375,7 @@
 	struct fwohci_softc *sc = (struct fwohci_softc *)fc;
 	int sleepch;
 
-	OWRITE(sc, OHCI_ITCTLCLR(dmach), 
+	OWRITE(sc, OHCI_ITCTLCLR(dmach),
 			OHCI_CNTL_DMA_RUN | OHCI_CNTL_CYCMATCH_S);
 	OWRITE(sc, OHCI_IT_MASKCLR, 1 << dmach);
 	OWRITE(sc, OHCI_IT_STATCLR, 1 << dmach);
@@ -1620,7 +1620,7 @@
 						OHCI_BRANCH_ALWAYS);
 #endif
 #if 0 /* if bulkxfer->npacket changes */
-			db[ldesc].db.desc.depend = db[0].db.desc.depend = 
+			db[ldesc].db.desc.depend = db[0].db.desc.depend =
 				((struct fwohcidb_tr *)
 				(chunk->start))->bus_addr | dbch->ndesc;
 #else
@@ -1813,9 +1813,9 @@
 	OWRITE(sc, FWOHCI_INTMASKCLR,
 			OHCI_INT_EN | OHCI_INT_ERR | OHCI_INT_PHY_SID
 			| OHCI_INT_PHY_INT
-			| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS 
+			| OHCI_INT_DMA_ATRQ | OHCI_INT_DMA_ATRS
 			| OHCI_INT_DMA_PRRQ | OHCI_INT_DMA_PRRS
-			| OHCI_INT_DMA_ARRQ | OHCI_INT_DMA_ARRS 
+			| OHCI_INT_DMA_ARRQ | OHCI_INT_DMA_ARRS
 			| OHCI_INT_PHY_BUS_R);
 
 	if (sc->fc.arq !=0 && sc->fc.arq->maxq > 0)
@@ -1827,7 +1827,7 @@
 
 #if defined(__NetBSD__)
 static void
-fwohci_power(int why, void *arg)
+fwohci_power(void *arg, int why)
 {
 	struct fwohci_softc *sc = arg;
 	int s;
@@ -1914,7 +1914,7 @@
 			stat & OHCI_INT_DMA_ARRQ  ? "DMA_ARRQ " :"",
 			stat & OHCI_INT_DMA_ATRS  ? "DMA_ATRS " :"",
 			stat & OHCI_INT_DMA_ATRQ  ? "DMA_ATRQ " :"",
-			stat, OREAD(sc, FWOHCI_INTMASK) 
+			stat, OREAD(sc, FWOHCI_INTMASK)
 		);
 #endif
 /* Bus reset */
@@ -1923,7 +1923,7 @@
 			goto busresetout;
 		/* Disable bus reset interrupt until sid recv. */
 		OWRITE(sc, FWOHCI_INTMASKCLR,  OHCI_INT_PHY_BUS_R);
-	
+
 		device_printf(fc->dev, "BUS reset\n");
 		OWRITE(sc, FWOHCI_INTMASKCLR,  OHCI_INT_CYC_LOST);
 		OWRITE(sc, OHCI_LNKCTLCLR, OHCI_CNTL_CYCSRC);
@@ -2034,7 +2034,7 @@
 		/* Set ATRetries register */
 		OWRITE(sc, OHCI_ATRETRY, 1<<(13+16) | 0xfff);
 /*
-** Checking whether the node is root or not. If root, turn on 
+** Checking whether the node is root or not. If root, turn on
 ** cycle master.
 */
 		node_id = OREAD(sc, FWOHCI_NODEID);
@@ -2157,7 +2157,7 @@
 	stat = OREAD(sc, FWOHCI_INTSTAT);
 	CTR1(KTR_DEV, "fwoch_check_stat 0x%08x", stat);
 	if (stat == 0xffffffff) {
-		device_printf(sc->fc.dev, 
+		device_printf(sc->fc.dev,
 			"device physically ejected?\n");
 		return(stat);
 	}
@@ -2281,7 +2281,7 @@
 		dump_db(sc, ITX_CH + dmach);
 	while ((chunk = STAILQ_FIRST(&it->stdma)) != NULL) {
 		db = ((struct fwohcidb_tr *)(chunk->end))->db;
-		stat = FWOHCI_DMA_READ(db[ldesc].db.desc.res) 
+		stat = FWOHCI_DMA_READ(db[ldesc].db.desc.res)
 				>> OHCI_STATUS_SHIFT;
 		db = ((struct fwohcidb_tr *)(chunk->start))->db;
 		/* timestamp */
@@ -2362,7 +2362,7 @@
 	}
 	splx(s);
 	if (w) {
-		if (ir->flag & FWXFERQ_HANDLER) 
+		if (ir->flag & FWXFERQ_HANDLER)
 			ir->hand(ir);
 		else
 			wakeup(ir);
@@ -2393,8 +2393,8 @@
 
 	device_printf(sc->fc.dev, "ch %1x cntl:0x%08x cmd:0x%08x match:0x%08x\n",
 		ch,
-		cntl, 
-		cmd, 
+		cntl,
+		cmd,
 		match);
 	stat &= 0xffff ;
 	if (stat) {
@@ -2554,7 +2554,7 @@
 			printf(" Nostat\n");
 		}
 		if(key == OHCI_KEY_ST2 ){
-			printf("0x%08x 0x%08x 0x%08x 0x%08x\n", 
+			printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
 				FWOHCI_DMA_READ(db[i+1].db.immed[0]),
 				FWOHCI_DMA_READ(db[i+1].db.immed[1]),
 				FWOHCI_DMA_READ(db[i+1].db.immed[2]),
@@ -2563,15 +2563,15 @@
 		if(key == OHCI_KEY_DEVICE){
 			return;
 		}
-		if((cmd & OHCI_BRANCH_MASK) 
+		if((cmd & OHCI_BRANCH_MASK)
 				== OHCI_BRANCH_ALWAYS){
 			return;
 		}
-		if((cmd & OHCI_CMD_MASK) 
+		if((cmd & OHCI_CMD_MASK)
 				== OHCI_OUTPUT_LAST){
 			return;
 		}
-		if((cmd & OHCI_CMD_MASK) 
+		if((cmd & OHCI_CMD_MASK)
 				== OHCI_INPUT_LAST){
 			return;
 		}
@@ -2642,8 +2642,8 @@
 		ohcifp->mode.stream.chtag = chtag;
 		ohcifp->mode.stream.tcode = 0xa;
 #if BYTE_ORDER == BIG_ENDIAN
-		FWOHCI_DMA_WRITE(db[1].db.immed[0], db[1].db.immed[0]); 
-		FWOHCI_DMA_WRITE(db[1].db.immed[1], db[1].db.immed[1]); 
+		FWOHCI_DMA_WRITE(db[1].db.immed[0], db[1].db.immed[0]);
+		FWOHCI_DMA_WRITE(db[1].db.immed[1], db[1].db.immed[1]);
 #endif
 
 		FWOHCI_DMA_CLEAR(db[2].db.desc.cmd, OHCI_COUNT_MASK);
@@ -3021,7 +3021,7 @@
 
 				if ((vec[nvec-1].iov_len -=
 					sizeof(struct fwohci_trailer)) == 0)
-					nvec--; 
+					nvec--;
 				rb.fc = &sc->fc;
 				rb.vec = vec;
 				rb.nvec = nvec;
@@ -3030,7 +3030,7 @@
 				break;
 			}
 			case FWOHCIEV_BUSRST:
-				if (sc->fc.status != FWBUSRESET) 
+				if (sc->fc.status != FWBUSRESET)
 					printf("got BUSRST packet!?\n");
 				break;
 			default:
@@ -3116,8 +3116,8 @@
 
 int
 fwohci_print(void *aux, const char *pnp)
-{       
-	char *name = aux;       
+{
+	char *name = aux;
 
 	if (pnp)
 		aprint_normal("%s at %s", name, pnp);
Index: sys/dev/isa/sbdsp.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/sbdsp.c,v
retrieving revision 1.122
diff -u -r1.122 sbdsp.c
--- sys/dev/isa/sbdsp.c	14 May 2006 21:42:27 -0000	1.122
+++ sys/dev/isa/sbdsp.c	25 May 2006 11:26:10 -0000
@@ -231,7 +231,7 @@
 
 int	sbdsp_midi_intr(void *);
 
-static void	sbdsp_powerhook(int, void*);
+static void	sbdsp_powerhook(void*, int);
 
 #ifdef AUDIO_DEBUG
 void	sb_printsc(struct sbdsp_softc *);
@@ -445,7 +445,7 @@
 }
 
 static void
-sbdsp_powerhook(int why, void *arg)
+sbdsp_powerhook(void *arg, int why)
 {
 	struct sbdsp_softc *sc;
 	int i;
@@ -2419,4 +2419,3 @@
 }
 
 #endif
-
Index: sys/dev/isa/ym.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/ym.c,v
retrieving revision 1.27
diff -u -r1.27 ym.c
--- sys/dev/isa/ym.c	24 Dec 2005 20:27:41 -0000	1.27
+++ sys/dev/isa/ym.c	25 May 2006 11:26:11 -0000
@@ -159,7 +159,7 @@
 #ifndef AUDIO_NO_POWER_CTL
 static void ym_save_codec_regs(struct ym_softc *);
 static void ym_restore_codec_regs(struct ym_softc *);
-void	ym_power_hook(int, void *);
+void	ym_power_hook(void *, int);
 int	ym_codec_power_ctl(void *, int);
 static void ym_chip_powerdown(struct ym_softc *);
 static void ym_chip_powerup(struct ym_softc *, int);
@@ -1104,14 +1104,14 @@
 }
 
 /*
- * Save and restore the state on suspending / resumning.
+ * Save and restore the state on suspending / resuming.
  *
  * XXX This is not complete.
  * Currently only the parameters, such as output gain, are restored.
  * DMA state should also be restored.  FIXME.
  */
 void
-ym_power_hook(int why, void *v)
+ym_power_hook(void *v, int why)
 {
 	struct ym_softc *sc;
 	int i, xmax;
Index: sys/dev/pci/agp_i810.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/agp_i810.c,v
retrieving revision 1.30
diff -u -r1.30 agp_i810.c
--- sys/dev/pci/agp_i810.c	14 May 2006 21:45:00 -0000	1.30
+++ sys/dev/pci/agp_i810.c	25 May 2006 11:26:11 -0000
@@ -104,7 +104,7 @@
 static int agp_i810_free_memory(struct agp_softc *, struct agp_memory *);
 static int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *, off_t);
 static int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *);
-static void agp_i810_powerhook(int, void *);
+static void agp_i810_powerhook(void *, int);
 
 static struct agp_methods agp_i810_methods = {
 	agp_i810_get_aperture,
@@ -756,7 +756,7 @@
 }
 
 static void
-agp_i810_powerhook(int why, void *arg)
+agp_i810_powerhook(void *arg, int why)
 {
 	struct agp_softc *sc = (struct agp_softc *)arg;
 	struct agp_i810_softc *isc = sc->as_chipc;
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	25 May 2006 11:26:11 -0000
@@ -74,7 +74,7 @@
 static int agp_intel_bind_page(struct agp_softc *, off_t, bus_addr_t);
 static int agp_intel_unbind_page(struct agp_softc *, off_t);
 static void agp_intel_flush_tlb(struct agp_softc *);
-static void agp_intel_powerhook(int, void *);
+static void agp_intel_powerhook(void *, int);
 
 static struct agp_methods agp_intel_methods = {
 	agp_intel_get_aperture,
@@ -393,7 +393,7 @@
 }
 
 static void
-agp_intel_powerhook(int why, void *opaque)
+agp_intel_powerhook(void *opaque, int why)
 {
 	struct agp_softc *sc;
 	struct agp_intel_softc *isc;
Index: sys/dev/pci/auacer.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auacer.c,v
retrieving revision 1.11
diff -u -r1.11 auacer.c
--- sys/dev/pci/auacer.c	11 Dec 2005 12:22:48 -0000	1.11
+++ sys/dev/pci/auacer.c	25 May 2006 11:26:11 -0000
@@ -194,7 +194,7 @@
 				struct auacer_dma *);
 static int	auacer_freemem(struct auacer_softc *, struct auacer_dma *);
 
-static void	auacer_powerhook(int, void *);
+static void	auacer_powerhook(void *, int);
 static int	auacer_set_rate(struct auacer_softc *, int, u_int);
 
 static void auacer_reset(struct auacer_softc *sc);
@@ -1028,7 +1028,7 @@
 }
 
 static void
-auacer_powerhook(int why, void *addr)
+auacer_powerhook(void *addr, int why)
 {
 	struct auacer_softc *sc;
 
Index: sys/dev/pci/auich.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auich.c,v
retrieving revision 1.107
diff -u -r1.107 auich.c
--- sys/dev/pci/auich.c	27 Apr 2006 12:21:39 -0000	1.107
+++ sys/dev/pci/auich.c	25 May 2006 11:26:12 -0000
@@ -287,7 +287,7 @@
 		    struct auich_dma *);
 static int	auich_freemem(struct auich_softc *, struct auich_dma *);
 
-static void	auich_powerhook(int, void *);
+static void	auich_powerhook(void *, int);
 static int	auich_set_rate(struct auich_softc *, int, u_long);
 static int	auich_sysctl_verify(SYSCTLFN_ARGS);
 static void	auich_finish_attach(struct device *);
@@ -755,7 +755,7 @@
 	sc->sc_audiodev = audio_attach_mi(&auich_hw_if, sc, &sc->sc_dev);
 
 #if notyet
-	auich_powerhook(PWR_SUSPEND, sc);
+	auich_powerhook(sc, PWR_SUSPEND);
 #endif
 
 	return;
@@ -1430,10 +1430,10 @@
 
 	switch (state) {
 	case AUDIOPOWER_OFF:
-		auich_powerhook(PWR_SUSPEND, sc);
+		auich_powerhook(sc, PWR_SUSPEND);
 		break;
 	case AUDIOPOWER_ON:
-		auich_powerhook(PWR_RESUME, sc);
+		auich_powerhook(sc, PWR_RESUME);
 		break;
 	default:
 		aprint_error("%s: unknown power state %d\n",
@@ -1558,7 +1558,7 @@
 }
 
 static void
-auich_powerhook(int why, void *addr)
+auich_powerhook(void *addr, int why)
 {
 	struct auich_softc *sc;
 	const int d0 = PCI_PWR_D0;
Index: sys/dev/pci/auixp.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auixp.c,v
retrieving revision 1.13
diff -u -r1.13 auixp.c
--- sys/dev/pci/auixp.c	14 May 2006 21:45:00 -0000	1.13
+++ sys/dev/pci/auixp.c	25 May 2006 11:26:12 -0000
@@ -168,7 +168,7 @@
 /* power management (do we support that already?) */
 static int	auixp_power(struct auixp_softc *, int);
 #if 0
-static void	auixp_powerhook(int, void *);
+static void	auixp_powerhook(void *, int);
 static int	auixp_suspend(struct auixp_softc *);
 static int	auixp_resume(struct auixp_softc *);
 #endif
@@ -1798,7 +1798,7 @@
 
 #if 0
 static void
-auixp_powerhook(int why, void *hdl)
+auixp_powerhook(void *hdl, int why)
 {
 	struct auixp_softc *sc;
 
Index: sys/dev/pci/autri.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/autri.c,v
retrieving revision 1.30
diff -u -r1.30 autri.c
--- sys/dev/pci/autri.c	8 Mar 2006 23:46:27 -0000	1.30
+++ sys/dev/pci/autri.c	25 May 2006 11:26:12 -0000
@@ -97,7 +97,7 @@
 static int	autri_reset_codec(void *);
 static enum ac97_host_flags	autri_flags_codec(void *);
 
-static void autri_powerhook(int, void *);
+static void autri_powerhook(void *, int);
 static int  autri_init(void *);
 static struct autri_dma *autri_find_dma(struct autri_softc *, void *);
 static void autri_setup_channel(struct autri_softc *, int,
@@ -604,7 +604,7 @@
     autri_match, autri_attach, NULL, NULL);
 
 static void
-autri_powerhook(int why, void *addr)
+autri_powerhook(void *addr, int why)
 {
 	struct autri_softc *sc;
 
Index: sys/dev/pci/auvia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auvia.c,v
retrieving revision 1.53
diff -u -r1.53 auvia.c
--- sys/dev/pci/auvia.c	28 Nov 2005 19:00:49 -0000	1.53
+++ sys/dev/pci/auvia.c	25 May 2006 11:26:13 -0000
@@ -116,7 +116,7 @@
 static int	auvia_trigger_input(void *, void *, void *, int,
 				    void (*)(void *), void *,
 				    const audio_params_t *);
-static void	auvia_powerhook(int, void *);
+static void	auvia_powerhook(void *, int);
 static int	auvia_intr(void *);
 
 CFATTACH_DECL(auvia, sizeof (struct auvia_softc),
@@ -1062,7 +1062,7 @@
 }
 
 static void
-auvia_powerhook(int why, void *addr)
+auvia_powerhook(void *addr, int why)
 {
 	struct auvia_softc *sc;
 
Index: sys/dev/pci/cs4280.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/cs4280.c,v
retrieving revision 1.38
diff -u -r1.38 cs4280.c
--- sys/dev/pci/cs4280.c	15 Apr 2006 21:20:47 -0000	1.38
+++ sys/dev/pci/cs4280.c	25 May 2006 11:26:13 -0000
@@ -109,7 +109,7 @@
 static enum ac97_host_flags cs4280_flags_codec(void *);
 
 /* For PowerHook */
-static void cs4280_power(int, void *);
+static void cs4280_power(void *, int);
 
 /* Internal functions */
 static const struct cs4280_card_t * cs4280_identify_card(struct pci_attach_args *);
@@ -899,7 +899,7 @@
 
 /* Power Hook */
 static void
-cs4280_power(int why, void *v)
+cs4280_power(void *v, int why)
 {
 	static uint32_t pctl = 0, pba = 0, pfie = 0, pdtc = 0;
 	static uint32_t cctl = 0, cba = 0, cie = 0;
Index: sys/dev/pci/cs4281.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/cs4281.c,v
retrieving revision 1.28
diff -u -r1.28 cs4281.c
--- sys/dev/pci/cs4281.c	15 Apr 2006 21:20:47 -0000	1.28
+++ sys/dev/pci/cs4281.c	25 May 2006 11:26:14 -0000
@@ -106,7 +106,7 @@
 static int      cs4281_init(struct cs428x_softc *, int);
 
 /* Power Management */
-static void cs4281_power(int, void *);
+static void cs4281_power(void *, int);
 
 static const struct audio_hw_if cs4281_hw_if = {
 	NULL,			/* open */
@@ -728,7 +728,7 @@
 
 /* Power Hook */
 static void
-cs4281_power(int why, void *v)
+cs4281_power(void *v, int why)
 {
 	static uint32_t dba0 = 0, dbc0 = 0, dmr0 = 0, dcr0 = 0;
 	static uint32_t dba1 = 0, dbc1 = 0, dmr1 = 0, dcr1 = 0;
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	25 May 2006 11:26:14 -0000
@@ -69,7 +69,7 @@
 
 static void ehci_get_ownership(ehci_softc_t *sc, pci_chipset_tag_t pc,
 			       pcitag_t tag);
-static void ehci_pci_powerhook(int, void *);
+static void ehci_pci_powerhook(void *, int);
 
 struct ehci_pci_softc {
 	ehci_softc_t		sc;
@@ -321,7 +321,7 @@
 }
 
 static void
-ehci_pci_powerhook(int why, void *opaque)
+ehci_pci_powerhook(void *opaque, int why)
 {
 	struct ehci_pci_softc *sc;
 	pci_chipset_tag_t pc;
Index: sys/dev/pci/esa.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esa.c,v
retrieving revision 1.31
diff -u -r1.31 esa.c
--- sys/dev/pci/esa.c	11 Dec 2005 12:22:49 -0000	1.31
+++ sys/dev/pci/esa.c	25 May 2006 11:26:14 -0000
@@ -162,7 +162,7 @@
 
 /* power management */
 static int		esa_power(struct esa_softc *, int);
-static void		esa_powerhook(int, void *);
+static void		esa_powerhook(void *, int);
 static int		esa_suspend(struct esa_softc *);
 static int		esa_resume(struct esa_softc *);
 
@@ -1649,7 +1649,7 @@
 }
 
 static void
-esa_powerhook(int why, void *hdl)
+esa_powerhook(void *hdl, int why)
 {
 	struct esa_softc *sc;
 
Index: sys/dev/pci/esm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esm.c,v
retrieving revision 1.34
diff -u -r1.34 esm.c
--- sys/dev/pci/esm.c	14 Apr 2006 19:08:30 -0000	1.34
+++ sys/dev/pci/esm.c	25 May 2006 11:26:14 -0000
@@ -147,7 +147,7 @@
 			    struct esm_chinfo *);
 
 /* Power Management */
-void esm_powerhook(int, void *);
+void esm_powerhook(void *, int);
 
 CFATTACH_DECL(esm, sizeof(struct esm_softc),
     esm_match, esm_attach, NULL, NULL);
@@ -1716,7 +1716,7 @@
 
 /* Power Hook */
 void
-esm_powerhook(int why, void *v)
+esm_powerhook(void *v, int why)
 {
 	struct esm_softc *ess;
 
Index: sys/dev/pci/if_bge.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_bge.c,v
retrieving revision 1.106
diff -u -r1.106 if_bge.c
--- sys/dev/pci/if_bge.c	27 Apr 2006 18:09:54 -0000	1.106
+++ sys/dev/pci/if_bge.c	25 May 2006 11:26:16 -0000
@@ -183,7 +183,7 @@
 
 static int	bge_probe(device_t, cfdata_t, void *);
 static void	bge_attach(device_t, device_t, void *);
-static void	bge_powerhook(int, void *);
+static void	bge_powerhook(void *, int);
 static void	bge_release_resources(struct bge_softc *);
 static void	bge_txeof(struct bge_softc *);
 static void	bge_rxeof(struct bge_softc *);
@@ -263,7 +263,7 @@
 
 /*
  * XXX: how to handle variants based on 5750 and derivatives:
- * 5750 5751, 5721, possibly 5714, 5752, and 5708?, which 
+ * 5750 5751, 5721, possibly 5714, 5752, and 5708?, which
  * in general behave like a 5705, except with additional quirks.
  * This driver's current handling of the 5721 is wrong;
  * how we map ASIC revision to "quirks" needs more thought.
@@ -1262,11 +1262,11 @@
 		    (0x2 << BGE_PCIDMARWCTL_WR_WAT_SHIFT));
 
 		/* jonathan: alternative from Linux driver */
-#define DMA_CTRL_WRITE_PCIE_H20MARK_128         0x00180000 
+#define DMA_CTRL_WRITE_PCIE_H20MARK_128         0x00180000
 #define DMA_CTRL_WRITE_PCIE_H20MARK_256         0x00380000
 
 		dma_rw_ctl =   0x76000000; /* XXX XXX XXX */;
-		device_ctl = pci_conf_read(pa->pa_pc, pa->pa_tag, 
+		device_ctl = pci_conf_read(pa->pa_pc, pa->pa_tag,
 					   BGE_PCI_CONF_DEV_CTRL);
 		printf("%s: pcie mode=0x%x\n", sc->bge_dev.dv_xname, device_ctl);
 
@@ -3444,7 +3444,7 @@
 	int			i = 0;
 	struct m_tag		*mtag;
 	int			use_tso, maxsegsize, error;
- 
+
 	cur = frag = *txidx;
 
 	if (m_head->m_pkthdr.csum_flags) {
@@ -3585,7 +3585,7 @@
 			csum_flags &= ~(BGE_TXBDFLAG_TCP_UDP_CSUM);
 		} else {
 			/*
-			 * XXX jonathan@NetBSD.org: 5705 untested. 
+			 * XXX jonathan@NetBSD.org: 5705 untested.
 			 * Requires TSO firmware patch for 5701/5703/5704.
 			 */
 			th->th_sum = in_cksum_phdr(ip->ip_src.s_addr,
@@ -3593,7 +3593,7 @@
 		}
 
 		mss = m_head->m_pkthdr.segsz;
-		txbd_tso_flags |= 	
+		txbd_tso_flags |=
 		    BGE_TXBDFLAG_CPU_PRE_DMA |
 		    BGE_TXBDFLAG_CPU_POST_DMA;
 
@@ -3644,7 +3644,7 @@
 		f = &sc->bge_rdata->bge_tx_ring[frag];
 		if (sc->bge_cdata.bge_tx_chain[frag] != NULL)
 			break;
-	
+
 		bge_set_hostaddr(&f->bge_addr, dmamap->dm_segs[i].ds_addr);
 		f->bge_len = dmamap->dm_segs[i].ds_len;
 
@@ -3831,7 +3831,7 @@
 
 	/* Specify MTU. */
 	CSR_WRITE_4(sc, BGE_RX_MTU, ifp->if_mtu +
-	    ETHER_HDR_LEN + ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN); 
+	    ETHER_HDR_LEN + ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN);
 
 	/* Load our MAC address. */
 	m = (u_int16_t *)&(LLADDR(ifp->if_sadl)[0]);
@@ -4254,7 +4254,7 @@
 }
 
 static void
-bge_powerhook(int why, void *hdl)
+bge_powerhook(void *hdl, int why)
 {
 	struct bge_softc *sc = (struct bge_softc *)hdl;
 	struct ifnet *ifp = &sc->ethercom.ec_if;
Index: sys/dev/pci/if_fxp_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_fxp_pci.c,v
retrieving revision 1.44
diff -u -r1.44 if_fxp_pci.c
--- sys/dev/pci/if_fxp_pci.c	10 Jan 2006 20:31:36 -0000	1.44
+++ sys/dev/pci/if_fxp_pci.c	25 May 2006 11:26:16 -0000
@@ -99,7 +99,7 @@
 static void	fxp_pci_disable(struct fxp_softc *);
 
 static void	fxp_pci_confreg_restore(struct fxp_pci_softc *psc);
-static void	fxp_pci_power(int why, void *arg);
+static void	fxp_pci_power(void *arg, int why);
 
 CFATTACH_DECL(fxp_pci, sizeof(struct fxp_pci_softc),
     fxp_pci_match, fxp_pci_attach, NULL, NULL);
@@ -239,7 +239,7 @@
  * on a resume.
  */
 static void
-fxp_pci_power(int why, void *arg)
+fxp_pci_power(void *arg, int why)
 {
 	struct fxp_pci_softc *psc = arg;
 
Index: sys/dev/pci/if_ipw.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_ipw.c,v
retrieving revision 1.25
diff -u -r1.25 if_ipw.c
--- sys/dev/pci/if_ipw.c	1 May 2006 20:43:46 -0000	1.25
+++ sys/dev/pci/if_ipw.c	25 May 2006 11:26:16 -0000
@@ -97,7 +97,7 @@
 static void	ipw_shutdown(void *);
 static int	ipw_suspend(struct ipw_softc *);
 static int	ipw_resume(struct ipw_softc *);
-static void	ipw_powerhook(int, void *);
+static void	ipw_powerhook(void *, int);
 
 static int	ipw_media_change(struct ifnet *);
 static void	ipw_media_status(struct ifnet *, struct ifmediareq *);
@@ -795,7 +795,7 @@
 }
 
 static void
-ipw_powerhook(int why, void *arg)
+ipw_powerhook(void *arg, int why)
 {
         struct ipw_softc *sc = arg;
 	int s;
@@ -1272,7 +1272,7 @@
 
 	case IPW_SBD_TYPE_HEADER:
 		shdr = sbd->priv;
- 		bus_dmamap_sync(sc->sc_dmat, sc->hdr_map, 
+ 		bus_dmamap_sync(sc->sc_dmat, sc->hdr_map,
  		    shdr->offset, sizeof(struct ipw_hdr), BUS_DMASYNC_POSTWRITE);
 		TAILQ_INSERT_TAIL(&sc->sc_free_shdr, shdr, next);
 		break;
@@ -1281,7 +1281,7 @@
 		ic = &sc->sc_ic;
 		sbuf = sbd->priv;
 
-		bus_dmamap_sync(sc->sc_dmat, sbuf->map, 
+		bus_dmamap_sync(sc->sc_dmat, sbuf->map,
 		    0, MCLBYTES, BUS_DMASYNC_POSTWRITE);
 		bus_dmamap_unload(sc->sc_dmat, sbuf->map);
 		m_freem(sbuf->m);
Index: sys/dev/pci/if_iwi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_iwi.c,v
retrieving revision 1.48
diff -u -r1.48 if_iwi.c
--- sys/dev/pci/if_iwi.c	14 May 2006 21:45:00 -0000	1.48
+++ sys/dev/pci/if_iwi.c	25 May 2006 11:26:17 -0000
@@ -95,7 +95,7 @@
 static void	iwi_shutdown(void *);
 static int	iwi_suspend(struct iwi_softc *);
 static int	iwi_resume(struct iwi_softc *);
-static void	iwi_powerhook(int, void *);
+static void	iwi_powerhook(void *, int);
 
 static int	iwi_alloc_cmd_ring(struct iwi_softc *, struct iwi_cmd_ring *,
     int);
@@ -372,7 +372,7 @@
 	    ether_sprintf(ic->ic_myaddr));
 
 	/* read the NIC type from EEPROM */
-	val = iwi_read_prom_word(sc, IWI_EEPROM_NIC_TYPE); 
+	val = iwi_read_prom_word(sc, IWI_EEPROM_NIC_TYPE);
 	sc->nictype = val & 0xff;
 
 	DPRINTF(("%s: NIC type %d\n", sc->sc_dev.dv_xname, sc->nictype));
@@ -844,7 +844,7 @@
 }
 
 static void
-iwi_powerhook(int why, void *arg)
+iwi_powerhook(void *arg, int why)
 {
         struct iwi_softc *sc = arg;
 	pci_chipset_tag_t pc = sc->sc_pct;
Index: sys/dev/pci/if_nfe.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_nfe.c,v
retrieving revision 1.3
diff -u -r1.3 if_nfe.c
--- sys/dev/pci/if_nfe.c	26 Mar 2006 00:34:14 -0000	1.3
+++ sys/dev/pci/if_nfe.c	25 May 2006 11:26:17 -0000
@@ -75,7 +75,7 @@
 
 int	nfe_match(struct device *, struct cfdata *, void *);
 void	nfe_attach(struct device *, struct device *, void *);
-void	nfe_power(int, void *);
+void	nfe_power(void *, int);
 void	nfe_miibus_statchg(struct device *);
 int	nfe_miibus_readreg(struct device *, int, int);
 void	nfe_miibus_writereg(struct device *, int, int, int);
@@ -330,7 +330,7 @@
 }
 
 void
-nfe_power(int why, void *arg)
+nfe_power(void *arg, int why)
 {
 	struct nfe_softc *sc = arg;
 	struct ifnet *ifp;
Index: sys/dev/pci/if_rtk_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_rtk_pci.c,v
retrieving revision 1.24
diff -u -r1.24 if_rtk_pci.c
--- sys/dev/pci/if_rtk_pci.c	9 Mar 2006 22:17:49 -0000	1.24
+++ sys/dev/pci/if_rtk_pci.c	25 May 2006 11:26:17 -0000
@@ -123,7 +123,7 @@
 
 static int	rtk_pci_match(struct device *, struct cfdata *, void *);
 static void	rtk_pci_attach(struct device *, struct device *, void *);
-static void	rtk_pci_powerhook(int, void *);
+static void	rtk_pci_powerhook(void *, int);
 
 CFATTACH_DECL(rtk_pci, sizeof(struct rtk_pci_softc),
     rtk_pci_match, rtk_pci_attach, NULL, NULL);
@@ -257,7 +257,7 @@
 }
 
 static void
-rtk_pci_powerhook(int why, void *arg)
+rtk_pci_powerhook(void *arg, int why)
 {
 	struct rtk_pci_softc *sc = (struct rtk_pci_softc *)arg;
 	int s;
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	25 May 2006 11:26:18 -0000
@@ -101,7 +101,7 @@
 static int	wi_pci_enable(struct wi_softc *);
 static void	wi_pci_disable(struct wi_softc *);
 static void	wi_pci_reset(struct wi_softc *);
-static void	wi_pci_powerhook(int, void *);
+static void	wi_pci_powerhook(void *, int);
 
 static const struct wi_pci_product
 	*wi_pci_lookup(struct pci_attach_args *);
@@ -390,7 +390,7 @@
 }
 
 static void
-wi_pci_powerhook(int why, void *arg)
+wi_pci_powerhook(void *arg, int why)
 {
 	struct wi_pci_softc *psc = arg;
 	struct wi_softc *sc = &psc->psc_wi;
Index: sys/dev/pci/neo.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/neo.c,v
retrieving revision 1.31
diff -u -r1.31 neo.c
--- sys/dev/pci/neo.c	25 Feb 2006 02:28:58 -0000	1.31
+++ sys/dev/pci/neo.c	25 May 2006 11:26:18 -0000
@@ -207,7 +207,7 @@
 static size_t	neo_round_buffersize(void *, int, size_t);
 static paddr_t	neo_mappage(void *, void *, off_t, int);
 static int	neo_get_props(void *);
-static void	neo_power(int, void *);
+static void	neo_power(void *, int);
 
 CFATTACH_DECL(neo, sizeof(struct neo_softc),
     neo_match, neo_attach, NULL, NULL);
@@ -551,7 +551,7 @@
 }
 
 static void
-neo_power(int why, void *addr)
+neo_power(void *addr, int why)
 {
 	struct neo_softc *sc;
 
Index: sys/dev/pci/pccbb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pccbb.c,v
retrieving revision 1.128
diff -u -r1.128 pccbb.c
--- sys/dev/pci/pccbb.c	5 Apr 2006 22:16:42 -0000	1.128
+++ sys/dev/pci/pccbb.c	25 May 2006 11:26:19 -0000
@@ -191,7 +191,7 @@
 
 static void pccbb_pcmcia_do_io_map(struct pcic_handle *, int);
 static void pccbb_pcmcia_do_mem_map(struct pcic_handle *, int);
-static void pccbb_powerhook(int, void *);
+static void pccbb_powerhook(void *, int);
 
 /* bus-space allocation and deallocation functions */
 #if rbus
@@ -3398,9 +3398,7 @@
 #endif /* rbus */
 
 static void
-pccbb_powerhook(why, arg)
-	int why;
-	void *arg;
+pccbb_powerhook(void *arg, int why)
 {
 	struct pccbb_softc *sc = arg;
 	pcireg_t reg;
Index: sys/dev/pci/piixide.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/piixide.c,v
retrieving revision 1.26
diff -u -r1.26 piixide.c
--- sys/dev/pci/piixide.c	19 May 2006 01:27:00 -0000	1.26
+++ sys/dev/pci/piixide.c	25 May 2006 11:26:19 -0000
@@ -49,7 +49,7 @@
 static u_int32_t piix_setup_sidetim_timings(u_int8_t, u_int8_t, u_int8_t);
 static void piixsata_chip_map(struct pciide_softc*, struct pci_attach_args *);
 
-static void piixide_powerhook(int, void *);
+static void piixide_powerhook(void *, int);
 static int  piixide_match(struct device *, struct cfdata *, void *);
 static void piixide_attach(struct device *, struct device *, void *);
 
@@ -223,7 +223,7 @@
 }
 
 static void
-piixide_powerhook(int why, void *hdl)
+piixide_powerhook(void *hdl, int why)
 {
 	struct pciide_softc *sc = (struct pciide_softc *)hdl;
 
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	25 May 2006 11:26:19 -0000
@@ -62,7 +62,7 @@
 #include <dev/usb/uhcireg.h>
 #include <dev/usb/uhcivar.h>
 
-static void	uhci_pci_powerhook(int, void *);
+static void	uhci_pci_powerhook(void *, int);
 
 struct uhci_pci_softc {
 	uhci_softc_t		sc;
@@ -217,7 +217,7 @@
 }
 
 static void
-uhci_pci_powerhook(int why, void *opaque)
+uhci_pci_powerhook(void *opaque, int why)
 {
 	struct uhci_pci_softc *sc;
 	pci_chipset_tag_t pc;
Index: sys/dev/pci/yds.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/yds.c,v
retrieving revision 1.30
diff -u -r1.30 yds.c
--- sys/dev/pci/yds.c	11 Dec 2005 12:22:51 -0000	1.30
+++ sys/dev/pci/yds.c	25 May 2006 11:26:20 -0000
@@ -190,7 +190,7 @@
 static struct yds_dma *yds_find_dma(struct yds_softc *, void *);
 
 static int	yds_init(struct yds_softc *);
-static void	yds_powerhook(int, void *);
+static void	yds_powerhook(void *, int);
 
 #ifdef AUDIO_DEBUG
 static void	yds_dump_play_slot(struct yds_softc *, int);
@@ -676,7 +676,7 @@
 }
 
 static void
-yds_powerhook(int why, void *addr)
+yds_powerhook(void *addr, int why)
 {
 	struct yds_softc *sc;
 
Index: sys/dev/pckbport/pms.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/pms.c,v
retrieving revision 1.10
diff -u -r1.10 pms.c
--- sys/dev/pckbport/pms.c	29 Mar 2006 07:11:08 -0000	1.10
+++ sys/dev/pckbport/pms.c	25 May 2006 11:26:20 -0000
@@ -87,7 +87,7 @@
 int	pms_ioctl(void *, u_long, caddr_t, int, struct lwp *);
 void	pms_disable(void *);
 #ifndef PMS_DISABLE_POWERHOOK
-void	pms_power(int, void *);
+void	pms_power(void *, int);
 #endif /* !PMS_DISABLE_POWERHOOK */
 
 const struct wsmouse_accessops pms_accessops = {
@@ -334,7 +334,7 @@
 
 #ifndef PMS_DISABLE_POWERHOOK
 void
-pms_power(int why, void *v)
+pms_power(void *v, int why)
 {
 	struct pms_softc *sc = v;
 
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	25 May 2006 11:26:20 -0000
@@ -310,7 +310,7 @@
 static int ray_match(struct device *, struct cfdata *, void *);
 static int ray_media_change(struct ifnet *);
 static void ray_media_status(struct ifnet *, struct ifmediareq *);
-void ray_power(int, void *);
+void ray_power(void *, int);
 static ray_cmd_func_t ray_rccs_intr(struct ray_softc *, bus_size_t);
 static void ray_read_region(struct ray_softc *, bus_size_t,void *,size_t);
 static void ray_recv(struct ray_softc *, bus_size_t);
@@ -885,9 +885,7 @@
 }
 
 void
-ray_power(why, arg)
-	int why;
-	void *arg;
+ray_power(void *arg, int why)
 {
 #if 0
 	struct ray_softc *sc;
Index: sys/dev/pcmcia/if_wi_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/if_wi_pcmcia.c,v
retrieving revision 1.68
diff -u -r1.68 if_wi_pcmcia.c
--- sys/dev/pcmcia/if_wi_pcmcia.c	11 Dec 2005 12:23:23 -0000	1.68
+++ sys/dev/pcmcia/if_wi_pcmcia.c	25 May 2006 11:26:21 -0000
@@ -79,7 +79,7 @@
 static int	wi_pcmcia_detach(struct device *, int);
 static int	wi_pcmcia_enable(struct wi_softc *);
 static void	wi_pcmcia_disable(struct wi_softc *);
-static void	wi_pcmcia_powerhook(int, void *);
+static void	wi_pcmcia_powerhook(void *, int);
 static void	wi_pcmcia_shutdown(void *);
 
 /* support to download firmware for symbol CF card */
@@ -413,9 +413,7 @@
 }
 
 static void
-wi_pcmcia_powerhook(why, arg)
-	int why;
-	void *arg;
+wi_pcmcia_powerhook(void *arg, int why)
 {
 	struct wi_pcmcia_softc *psc = arg;
 	struct wi_softc *sc = &psc->sc_wi;
Index: sys/dev/sbus/dbri.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sbus/dbri.c,v
retrieving revision 1.4
diff -u -r1.4 dbri.c
--- sys/dev/sbus/dbri.c	9 Mar 2006 20:44:18 -0000	1.4
+++ sys/dev/sbus/dbri.c	25 May 2006 11:26:21 -0000
@@ -7,8 +7,8 @@
  * Copyright (c) 2005 Michael Lorenz <macallan@netbsd.org>
  * All rights reserved.
  *
- * This driver is losely based on a Linux driver written by Rudolf Koenig and 
- * Brent Baccala who kindly gave their permission to use their code in a 
+ * This driver is losely based on a Linux driver written by Rudolf Koenig and
+ * Brent Baccala who kindly gave their permission to use their code in a
  * BSD-licensed driver.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -21,7 +21,7 @@
  *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software
  *    must display the following acknowledgement:
- *	This product includes software developed by Rudolf Koenig, Brent 
+ *	This product includes software developed by Rudolf Koenig, Brent
  *      Baccala, Jared D. McNeill.
  * 4. Neither the name of the author nor the names of any contributors may
  *    be used to endorse or promote products derived from this software
@@ -131,7 +131,7 @@
 /* pipe subroutines */
 static void	pipe_setup(struct dbri_softc *, int, int);
 static void	pipe_reset(struct dbri_softc *, int);
-static void	pipe_receive_fixed(struct dbri_softc *, int, 
+static void	pipe_receive_fixed(struct dbri_softc *, int,
     volatile u_int32_t *);
 static void	pipe_transmit_fixed(struct dbri_softc *, int, u_int32_t);
 
@@ -156,7 +156,7 @@
 static void
 setup_ring(struct dbri_softc *, int, int, int, int, void (*)(void *), void *);
 
-static int	dbri_trigger_output(void *, void *, void *, int, 
+static int	dbri_trigger_output(void *, void *, void *, int,
     void (*)(void *), void *, const struct audio_params *);
 
 static void	*dbri_malloc(void *, int, size_t, struct malloc_type *, int);
@@ -164,7 +164,7 @@
 static paddr_t	dbri_mappage(void *, void *, off_t, int);
 static void	dbri_set_power(struct dbri_softc *, int);
 static void	dbri_bring_up(struct dbri_softc *);
-static void	dbri_powerhook(int, void *);
+static void	dbri_powerhook(void *, int);
 
 /* stupid support routines */
 static u_int32_t	reverse_bytes(u_int32_t, int);
@@ -213,7 +213,7 @@
 	DBRI_ENABLE_MONO,
 	DBRI_ENABLE_HEADPHONE,
 	DBRI_ENABLE_LINE
-/*	
+/*
 	DBRI_INPUT_CLASS,
 	DBRI_RECORD_CLASS,
 	DBRI_INPUT_GAIN,
@@ -257,14 +257,14 @@
 	sc->sc_iot = sa->sa_bustag;
 	sc->sc_dmat = sa->sa_dmatag;
 	sc->sc_powerstate = PWR_RESUME;
-	
+
 	pwr = prom_getpropint(sa->sa_node,"pwr-on-auxio",0);
 	if(pwr) {
-		/* 
+		/*
 		 * we can control DBRI power via auxio and we're initially
 		 * powered down
 		 */
-		
+
 		sc->sc_have_powerctl = 1;
 		sc->sc_powerstate = 0;
 		printf("\n");
@@ -276,7 +276,7 @@
 		sc->sc_powerstate = 1;
 		printf(": rev %s\n", ver);
 	}
-	
+
 	if (sa->sa_npromvaddrs)
 		ioh = (bus_space_handle_t)sa->sa_promvaddrs[0];
 	else {
@@ -341,7 +341,7 @@
 
 	sc->sc_locked = 0;
 	sc->sc_desc_used = 0;
-	
+
 	config_interrupts(self, &dbri_config_interrupts);
 
 	return;
@@ -354,12 +354,12 @@
 dbri_set_power(struct dbri_softc *sc, int state)
 {
 	int s;
-	
+
 	if (sc->sc_have_powerctl == 0)
 		return;
 	if (sc->sc_powerstate == state)
 		return;
-	
+
 	if (state) {
 		DPRINTF(("%s: waiting to power up... ", sc->sc_dev.dv_xname));
 		s = splhigh();
@@ -387,7 +387,7 @@
 		return;
 	if (sc->sc_powerstate == 1)
 		return;
-	
+
 	/* ok, we really need to do something */
 	dbri_set_power(sc, 1);
 
@@ -410,7 +410,7 @@
 	mmcodec_init(sc);
 	/* Attach ourselves to the high level audio interface */
 	audio_attach_mi(&dbri_hw_if, sc, &sc->sc_dev);
-	
+
 	/* power down until open() */
 	dbri_set_power(sc, 0);
 	return;
@@ -479,27 +479,27 @@
 	/* XXX: Initialize interrupt ring buffer */
 	sc->sc_dma->intr[0] = (u_int32_t)sc->sc_dmabase + dbri_dma_off(intr, 0);
 	sc->sc_irqp = 1;
-	
+
 	/* Initialize pipes */
 	for (n = 0; n < DBRI_PIPE_MAX; n++)
 		sc->sc_pipe[n].desc = sc->sc_pipe[n].next = -1;
-	
+
 	for(n=1;n<DBRI_INT_BLOCKS;n++) {
 		sc->sc_dma->intr[n]=0;
 	}
-			
+
 	/* Disable all SBus bursts */
 	/* XXX 16 byte bursts cause errors, the rest works */
 	reg = bus_space_read_4(iot, ioh, DBRI_REG0);
 	/*reg &= ~(DBRI_BURST_4 | DBRI_BURST_8 | DBRI_BURST_16);*/
 	reg |= (DBRI_BURST_4 | DBRI_BURST_8);
 	bus_space_write_4(iot, ioh, DBRI_REG0, reg);
-	
+
 	/* setup interrupt queue */
 	dmaaddr = (u_int32_t)sc->sc_dmabase + dbri_dma_off(intr, 0);
 	*(cmd++) = DBRI_CMD(DBRI_COMMAND_IIQ, 0, 0);
 	*(cmd++) = dmaaddr;
-			
+
 	dbri_command_send(sc, cmd);
 	return (0);
 }
@@ -512,8 +512,8 @@
 	bus_space_handle_t ioh = sc->sc_ioh;
 
 	bus_space_write_4(iot, ioh, DBRI_REG0, DBRI_SOFT_RESET);
-	while ((bus_space_read_4(iot, ioh, DBRI_REG0) & DBRI_SOFT_RESET) && 
-	    (bail < 100000)) { 
+	while ((bus_space_read_4(iot, ioh, DBRI_REG0) & DBRI_SOFT_RESET) &&
+	    (bail < 100000)) {
 		bail++;
 		delay(10);
 	}
@@ -629,7 +629,7 @@
 
 		td = sc->sc_pipe[channel].desc;
 		dd = &sc->sc_desc[td];
-		
+
 		if (dd->callback != NULL)
 			dd->callback(dd->callback_args);
 		break;
@@ -714,7 +714,7 @@
 
 	reg2 = bus_space_read_4(iot, ioh, DBRI_REG2);
 	DPRINTF(("mmcodec_init: PIO reads %x\n", reg2));
-	
+
 	if (reg2 & DBRI_PIO2) {
 		printf("%s: onboard CS4215 detected\n",
 		    sc->sc_dev.dv_xname);
@@ -752,7 +752,7 @@
 		return (-1);
 	}
 
-	printf("%s: cs4215 ver %d found at offset %d\n", 
+	printf("%s: cs4215 ver %d found at offset %d\n",
 	    sc->sc_dev.dv_xname, sc->sc_version & 0xf, sc->sc_mm.offset);
 
 	/* set some sane defaults for mmcodec_init_data */
@@ -780,9 +780,9 @@
 
 	/* switch CS4215 to data mode - set PIO3 to 1 */
 	tmp = DBRI_PIO_ENABLE_ALL | DBRI_PIO1 | DBRI_PIO3;
-/* XXX */	
+/* XXX */
 	tmp |= (sc->sc_mm.onboard ? DBRI_PIO0 : DBRI_PIO2);
-	
+
 	bus_space_write_4(iot, ioh, DBRI_REG2, tmp);
 	chi_reset(sc, CHIslave, 128);
 
@@ -851,7 +851,7 @@
 	mm->control[0] = CS4215_RSRVD_1 | CS4215_MLB;
 	mm->control[1] = CS4215_DFR_ULAW | CS4215_FREQ[0].csval;
 	mm->control[2] = CS4215_XCLK | CS4215_BSEL_128 | CS4215_FREQ[0].xtal;
-	mm->control[3] = 0; 
+	mm->control[3] = 0;
 
 	return;
 }
@@ -881,10 +881,10 @@
 	if (sc->sc_powerstate == 0)
 		return;
 	pipe_transmit_fixed(sc, 20, *(u_int32_t *)__UNVOLATILE(sc->sc_mm.data));
-	
+
 	/* give the chip some time to execure the command */
 	delay(250);
-	
+
 	return;
 }
 
@@ -941,7 +941,7 @@
 	tmp = bus_space_read_4(iot, ioh, DBRI_REG0);
 	tmp |= DBRI_CHI_ACTIVATE;
 	bus_space_write_4(iot, ioh, DBRI_REG0, tmp);
-	
+
 #if 1
 	i = 1024;
 	while (((sc->sc_mm.status & 0xe4) != 0x20) && --i) {
@@ -959,7 +959,7 @@
 		tsleep(sc, PCATCH | PZERO, "dbrifxdt", 0);
 	}
 #endif
-	
+
 	/* copy the version information before it becomes unreadable again */
 	sc->sc_version=sc->sc_mm.version;
 
@@ -973,7 +973,7 @@
 	mmcodec_setgain(sc, 0);
 
 	return (0);
-	
+
 }
 
 /*
@@ -1096,7 +1096,7 @@
 	desc = sc->sc_pipe[pipe].desc;
 
 	dd = &sc->sc_desc[desc];
-	
+
 	dd->busy = 0;
 
 	#if 0
@@ -1215,7 +1215,7 @@
 
 	for (i = 0; i < (num-1); i++) {
 
-		sc->sc_dma->desc[i].flags = TX_BCNT(blksz) 
+		sc->sc_dma->desc[i].flags = TX_BCNT(blksz)
 		    | TX_EOF | TX_BINT;
 		sc->sc_dma->desc[i].ba = dmabuf;
 		sc->sc_dma->desc[i].nda = dmabase + dbri_dma_off(desc, i + 1);
@@ -1224,12 +1224,12 @@
 		td_last = td;
 		dmabuf += blksz;
 	}
-	
+
 	sc->sc_dma->desc[i].flags = TX_BCNT(blksz) | TX_EOF | TX_BINT;
 	sc->sc_dma->desc[i].ba = dmabuf;
 	sc->sc_dma->desc[i].nda = dmabase + dbri_dma_off(desc, 0);
 	sc->sc_dma->desc[i].status = 0;
-		
+
 	dd->callback = callback; //sc->intr;
 	dd->callback_args = callback_args; //sc->intrarg;
 
@@ -1516,7 +1516,7 @@
 {
 
 	/* DBRI DMA segment size, rounded town to 32bit alignment */
-	return 0x1ffc;	
+	return 0x1ffc;
 }
 
 int
@@ -1547,8 +1547,8 @@
 	    case DBRI_VOL_OUTPUT:	/* master volume */
 		latt = (latt & 0xc0) | (63 -
 		    min(mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] >> 2, 63));
-		ratt = (ratt & 0xc0) | (63 - 
-		    min(mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] >> 2, 63));  
+		ratt = (ratt & 0xc0) | (63 -
+		    min(mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] >> 2, 63));
 		break;
 	    case DBRI_ENABLE_MONO:	/* built-in speaker */
 	    	if (mc->un.ord == 1) {
@@ -1569,13 +1569,13 @@
 			latt &= ~CS4215_LE;
 		break;
 	}
-		
+
 	sc->sc_latt = latt;
 	sc->sc_ratt = ratt;
 
 	/* no need to do that here - mmcodec_setgain does it anyway */
 	/*pipe_transmit_fixed(sc, 20, *(int *)__UNVOLATILE(sc->sc_mm.data));*/
-	
+
 	mmcodec_setgain(sc, 0);
 
 	return (0);
@@ -1588,7 +1588,7 @@
 
 	switch (mc->dev) {
 	    case DBRI_VOL_OUTPUT:	/* master volume */
-		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 
+		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
 		    (63 - (sc->sc_latt & 0x3f)) << 2;
 		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
 		    (63 - (sc->sc_ratt & 0x3f)) << 2;
@@ -1659,7 +1659,7 @@
 		di->un.e.member[1].ord = 1;
 		return (0);
 	}
-	
+
 	return (ENXIO);
 }
 
@@ -1691,7 +1691,7 @@
 
 	count = (unsigned long)(((caddr_t)end - (caddr_t)start));
 	num = count / blksize;
-	
+
 	DPRINTF(("trigger_output(%lx %lx) : %d %ld %ld\n",
 	    (unsigned long)intr,
 	    (unsigned long)intrarg, blksize, count, num));
@@ -1701,10 +1701,10 @@
 	mmcodec_setcontrol(sc);
 	mmcodec_init_data(sc);
 	current = 0;
-	while ((current < sc->sc_desc_used) && 
-	    (sc->sc_desc[current].buf != start)) 
+	while ((current < sc->sc_desc_used) &&
+	    (sc->sc_desc[current].buf != start))
 	    	current++;
-	
+
 	if (current < sc->sc_desc_used) {
 		setup_ring(sc, 4, current, num, blksize, intr, intrarg);
 		return 0;
@@ -1742,23 +1742,23 @@
 	struct dbri_softc *sc = v;
 	struct dbri_desc *dd = &sc->sc_desc[sc->sc_desc_used];
 	int rseg;
-	
-	if (bus_dmamap_create(sc->sc_dmat, s, 1, s, 0, BUS_DMA_NOWAIT, 
+
+	if (bus_dmamap_create(sc->sc_dmat, s, 1, s, 0, BUS_DMA_NOWAIT,
 	    &dd->dmamap) == 0) {
 		if (bus_dmamem_alloc(sc->sc_dmat, s, 0, 0, &dd->dmaseg,
 		    1, &rseg, BUS_DMA_NOWAIT) == 0) {
 			if (bus_dmamem_map(sc->sc_dmat, &dd->dmaseg, rseg, s,
-			    &dd->buf, BUS_DMA_NOWAIT|BUS_DMA_COHERENT) == 0) { 	
+			    &dd->buf, BUS_DMA_NOWAIT|BUS_DMA_COHERENT) == 0) {
 				if (dd->buf!=NULL) {
-					if (bus_dmamap_load(sc->sc_dmat, 
-					    dd->dmamap, dd->buf, s, NULL, 
+					if (bus_dmamap_load(sc->sc_dmat,
+					    dd->dmamap, dd->buf, s, NULL,
 					    BUS_DMA_NOWAIT) == 0) {
 						dd->len = s;
 						dd->busy = 0;
 						dd->callback = NULL;
-						dd->dmabase = 
+						dd->dmabase =
 						 dd->dmamap->dm_segs[0].ds_addr;
-						DPRINTF(("dbri_malloc: using buffer %d\n", 		
+						DPRINTF(("dbri_malloc: using buffer %d\n",
 						    sc->sc_desc_used));
 						sc->sc_desc_used++;
 						return dd->buf;
@@ -1788,20 +1788,20 @@
 {
 	struct dbri_softc *sc = v;;
 	int current;
-	
+
 	if (off < 0)
 		return -1;
-		
+
 	current = 0;
-	while ((current < sc->sc_desc_used) && 
-	    (sc->sc_desc[current].buf != mem)) 
+	while ((current < sc->sc_desc_used) &&
+	    (sc->sc_desc[current].buf != mem))
 	    	current++;
-	
+
 	if (current < sc->sc_desc_used) {
-		return bus_dmamem_mmap(sc->sc_dmat, 
+		return bus_dmamem_mmap(sc->sc_dmat,
 		    &sc->sc_desc[current].dmaseg, 1, off, prot, BUS_DMA_WAITOK);
 	}
-	
+
 	return -1;
 }
 
@@ -1809,7 +1809,7 @@
 dbri_open(void *cookie, int flags)
 {
 	struct dbri_softc *sc = cookie;
-	
+
 	dbri_bring_up(sc);
 	return 0;
 }
@@ -1818,15 +1818,15 @@
 dbri_close(void *cookie)
 {
 	struct dbri_softc *sc = cookie;
-	
+
 	dbri_set_power(sc, 0);
 }
 
 static void
-dbri_powerhook(int why, void *cookie)
+dbri_powerhook(void *cookie, int why)
 {
 	struct dbri_softc *sc = cookie;
-	
+
 	switch(why)
 	{
 		case PWR_SUSPEND:
@@ -1838,6 +1838,5 @@
 			break;
 	}
 }
-				
-#endif /* NAUDIO > 0 */
 
+#endif /* NAUDIO > 0 */
Index: sys/dev/sbus/p9100.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sbus/p9100.c,v
retrieving revision 1.32
diff -u -r1.32 p9100.c
--- sys/dev/sbus/p9100.c	15 Apr 2006 17:48:23 -0000	1.32
+++ sys/dev/sbus/p9100.c	25 May 2006 11:26:22 -0000
@@ -117,7 +117,7 @@
 
 	volatile uint32_t sc_junk;
 	uint32_t sc_mono_width;	/* for setup_mono */
-	
+
 	uint32_t sc_width;
 	uint32_t sc_height;	/* panel width / height */
 	uint32_t sc_stride;
@@ -201,8 +201,8 @@
 static void 	p9100_rectfill(void *, int, int, int, int, uint32_t);
 static void	p9100_clearscreen(struct p9100_softc *);
 
-static void	p9100_setup_mono(struct p9100_softc *, int, int, int, int, 
-		    uint32_t, uint32_t); 
+static void	p9100_setup_mono(struct p9100_softc *, int, int, int, int,
+		    uint32_t, uint32_t);
 static void	p9100_feed_line(struct p9100_softc *, int, uint8_t *);
 static void	p9100_set_color_reg(struct p9100_softc *, int, int32_t);
 
@@ -224,7 +224,7 @@
 		
 /*static int	p9100_load_font(void *, void *, struct wsdisplay_font *);*/
 
-static void	p9100_init_screen(void *, struct vcons_screen *, int, 
+static void	p9100_init_screen(void *, struct vcons_screen *, int,
 	    long *);
 #endif
 
@@ -237,7 +237,7 @@
 static int	p9100_intr(void *);
 
 /* power management stuff */
-static void p9100_power_hook(int, void *);
+static void p9100_power_hook(void *, int);
 
 static void p9100_set_extvga(void *, int);
 
@@ -316,13 +316,13 @@
 	fb->fb_type.fb_type = FBTYPE_P9100;
 #endif
 	fb->fb_pixels = NULL;
-	
+
 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
 
 	node = sa->sa_node;
 	isconsole = fb_is_console(node);
 	if (!isconsole) {
-		printf("\n%s: fatal error: PROM didn't configure device\n", 
+		printf("\n%s: fatal error: PROM didn't configure device\n",
 		    self->dv_xname);
 		return;
 	}
@@ -336,9 +336,9 @@
 	if (sbus_bus_map(sc->sc_bustag,
 			 sa->sa_reg[0].oa_space,
 			 sa->sa_reg[0].oa_base,
-			 /* 
-			  * XXX for some reason the SBus resources don't cover 
-			  * all registers, so we just map what we need 
+			 /*
+			  * XXX for some reason the SBus resources don't cover
+			  * all registers, so we just map what we need
 			  */
 			 /*sc->sc_ctl_psize*/ 0x8000,
 			 /*BUS_SPACE_MAP_LINEAR*/0, &sc->sc_ctl_memh) != 0) {
@@ -374,26 +374,26 @@
 	    }
 	}
 	sc->sc_depth = (fb->fb_type.fb_depth >> 3);
-	
+
 	/* XXX for some reason I get a kernel trap with this */
 	sc->sc_width = prom_getpropint(node, "width", 800);
 	sc->sc_height = prom_getpropint(node, "height", 600);
-	
-	sc->sc_stride = prom_getpropint(node, "linebytes", sc->sc_width * 
+
+	sc->sc_stride = prom_getpropint(node, "linebytes", sc->sc_width *
 	    (fb->fb_type.fb_depth >> 3));
 
 	/* check the RAMDAC */
 	ver = p9100_ramdac_read_ctl(sc, DAC_VERSION);
-	
+
 	p9100_init_engine(sc);
-	
-	fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height, 
+
+	fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height,
 	    node);
 
 	sbus_establish(&sc->sc_sd, &sc->sc_dev);
 	bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
 	    p9100_intr, sc);
-	    
+
 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
 	printf(": rev %d / %x, %dx%d, depth %d mem %x",
 	       (i & 7), ver, fb->fb_type.fb_width, fb->fb_type.fb_height,
@@ -433,26 +433,26 @@
 #endif
 	} else
 		printf("\n");
-		
+
 #if NWSDISPLAY > 0
 	wsfont_init();
-	
+
 	vcons_init(&sc->vd, sc, &p9100_defscreendesc, &p9100_accessops);
 	sc->vd.init_screen = p9100_init_screen;
-	
+
 	vcons_init_screen(&sc->vd, &p9100_console_screen, 1, &defattr);
 	p9100_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
 
 	sc->sc_bg = (defattr >> 16) & 0xff;
 	p9100_clearscreen(sc);
-	
+
 	ri = &p9100_console_screen.scr_ri;
 
 	p9100_defscreendesc.nrows = ri->ri_rows;
 	p9100_defscreendesc.ncols = ri->ri_cols;
 	p9100_defscreendesc.textops = &ri->ri_ops;
 	p9100_defscreendesc.capabilities = ri->ri_caps;
-	
+
 	if(isconsole) {
 		wsdisplay_cnattach(&p9100_defscreendesc, ri, 0, 0, defattr);
 	}
@@ -474,7 +474,7 @@
 	sc->sc_video = 1;
 	sc->sc_powerstate = PWR_RESUME;
 	powerhook_establish(p9100_power_hook, sc);
-	
+
 #if NTCTRL > 0
 	/* register callback for external monitor status change */
 	tadpole_register_callback(p9100_set_extvga, sc);
@@ -486,7 +486,7 @@
 	void *arg;
 {
 	struct p9100_softc *sc = arg;
-	
+
 #ifdef RASTERCONSOLE
 	sc->sc_cmap.cm_map[0][0] = 0xff;
 	sc->sc_cmap.cm_map[0][1] = 0xff;
@@ -580,7 +580,7 @@
 			if (error)
 				return error;
 		}
-		
+
 		p->cmap.index = 0;
 		p->cmap.count = 3;
 		if (p->cmap.red != NULL) {
@@ -595,7 +595,7 @@
 		int count;
 		uint32_t image[0x80], mask[0x80];
 		uint8_t red[3], green[3], blue[3];
-		
+
 		v = p->set;
 		if (v & FB_CUR_SETCMAP) {
 			error = copyin(p->cmap.red, red, 3);
@@ -628,14 +628,14 @@
 				pc->pc_hot = p->hot;
 			p9100_set_fbcursor(sc);
 		}
-		
+
 		if (v & FB_CUR_SETCMAP) {
 			memcpy(pc->red, red, 3);
 			memcpy(pc->green, green, 3);
 			memcpy(pc->blue, blue, 3);
 			p9100_setcursorcmap(sc);
 		}
-		
+
 		if (v & FB_CUR_SETSHAPE) {
 			memcpy(pc->pc_bits, image, 0x200);
 			memcpy(&pc->pc_bits[0x80], mask, 0x200);
@@ -689,7 +689,7 @@
 p9100_init_engine(struct p9100_softc *sc)
 {
 	/* reset clipping rectangles */
-	uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) | 
+	uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) |
 	    (sc->sc_height & 0x3fff);
 
 	sc->sc_last_offset = 0xffffffff;
@@ -700,11 +700,11 @@
 	p9100_ctl_write_4(sc, BYTE_CLIP_MIN, 0);
 	p9100_ctl_write_4(sc, BYTE_CLIP_MAX, rmax);
 	p9100_ctl_write_4(sc, DRAW_MODE, 0);
-	p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);	
-	p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);	
-	p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);	
-	p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);	
-	p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);	
+	p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);
+	p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);
+	p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);
+	p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);
+	p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);
 }
 
 /* we only need these in the wsdisplay case */
@@ -714,23 +714,23 @@
 static void
 p9100_sync(struct p9100_softc *sc)
 {
-	while((p9100_ctl_read_4(sc, ENGINE_STATUS) & 
+	while((p9100_ctl_read_4(sc, ENGINE_STATUS) &
 	    (ENGINE_BUSY | BLITTER_BUSY)) != 0);
 }
 
-static void	
+static void
 p9100_set_color_reg(struct p9100_softc *sc, int reg, int32_t col)
 {
 	uint32_t out;
-	
+
 	switch(sc->sc_depth)
 	{
 		case 1:	/* 8 bit */
 			out = (col << 8) | col;
-			out |= out << 16;	
+			out |= out << 16;
 			break;
 		case 2: /* 16 bit */
-			out = col | (col << 16);	
+			out = col | (col << 16);
 			break;
 		default:
 			out = col;
@@ -739,7 +739,7 @@
 }
 
 /* screen-to-screen blit */
-static void 
+static void
 p9100_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
     int he, uint32_t rop)
 {
@@ -754,9 +754,9 @@
 	dstw = (((xd + wi - 1) & 0x3fff) << 16) | ((yd + he - 1) & 0x3fff);
 	p9100_sync(sc);
 	p9100_ctl_write_4(sc, RASTER_OP, rop);
-	
+
 	p9100_ctl_write_4(sc, ABS_XY0, src);
-	
+
 	p9100_ctl_write_4(sc, ABS_XY1, srcw);
 	p9100_ctl_write_4(sc, ABS_XY2, dst);
 	p9100_ctl_write_4(sc, ABS_XY3, dstw);
@@ -764,7 +764,7 @@
 }
 
 /* solid rectangle fill */
-static void 
+static void
 p9100_rectfill(void *cookie, int xs, int ys, int wi, int he, uint32_t col)
 {
 	struct p9100_softc *sc = cookie;
@@ -785,19 +785,19 @@
 }
 
 /* setup for mono->colour expansion */
-static void 
-p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he, 
-    uint32_t fg, uint32_t bg) 
+static void
+p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he,
+    uint32_t fg, uint32_t bg)
 {
 
 	sc->sc_last_offset = 0xffffffff;
 
 	p9100_sync(sc);
-	/* 
+	/*
 	 * this doesn't make any sense to me either, but for some reason the
-	 * chip applies the foreground colour to 0 pixels 
+	 * chip applies the foreground colour to 0 pixels
 	 */
-	 
+
 	p9100_set_color_reg(sc,FOREGROUND_COLOR,bg);
 	p9100_set_color_reg(sc,BACKGROUND_COLOR,fg);
 
@@ -811,7 +811,7 @@
 }
 
 /* write monochrome data to the screen through the blitter */
-static void 
+static void
 p9100_feed_line(struct p9100_softc *sc, int count, uint8_t *data)
 {
 	int i;
@@ -829,14 +829,14 @@
 			if (to_go > 31) {
 				bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
 				    (PIXEL_1 + (31 << 2)), latch);
-				/*p9100_ctl_write_4(sc, (PIXEL_1 + 
+				/*p9100_ctl_write_4(sc, (PIXEL_1 +
 				    (31 << 2)), latch);*/
 				to_go -= 32;
 			} else
 			{
 				bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
 				    (PIXEL_1 + ((to_go - 1) << 2)), latch);
-				/*p9100_ctl_write_4(sc, (PIXEL_1 + 
+				/*p9100_ctl_write_4(sc, (PIXEL_1 +
 				    ((to_go - 1) << 2)), latch);*/
 				to_go = 0;
 			}
@@ -847,12 +847,12 @@
 		}
 	if (shift != 24)
 		p9100_ctl_write_4(sc, (PIXEL_1 + ((to_go - 1) << 2)), latch);
-}	
+}
 
 static void
 p9100_clearscreen(struct p9100_softc *sc)
 {
-	
+
 	p9100_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
 }
 #endif /* NWSDISPLAY > 0 */
@@ -862,7 +862,7 @@
 {
 
 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
-	return ((bus_space_read_4(sc->sc_bustag, 
+	return ((bus_space_read_4(sc->sc_bustag,
 	    sc->sc_ctl_memh, off) >> 16) & 0xff);
 }
 
@@ -871,7 +871,7 @@
 {
 
 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
-	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off, 
+	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off,
 	    ((uint32_t)v) << 16);
 }
 
@@ -898,10 +898,10 @@
 p9100unblank(struct device *dev)
 {
 	struct p9100_softc *sc = (struct p9100_softc *)dev;
-	
+
 	p9100_set_video((struct p9100_softc *)dev, 1);
-	
-	/* 
+
+	/*
 	 * Check if we're in terminal mode. If not force the console screen
 	 * to front so we can see ddb, panic messages and so on
 	 */
@@ -920,7 +920,7 @@
 p9100_set_video(struct p9100_softc *sc, int enable)
 {
 	u_int32_t v = p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1);
-	
+
 	if (enable)
 		v |= VIDEO_ENABLED;
 	else
@@ -939,14 +939,14 @@
 	return (p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1) & VIDEO_ENABLED) != 0;
 }
 
-static void 
-p9100_power_hook(int why, void *cookie)
+static void
+p9100_power_hook(void *cookie, int why)
 {
 	struct p9100_softc *sc = cookie;
-	
+
 	if (why == sc->sc_powerstate)
 		return;
-		
+
 	switch(why)
 	{
 		case PWR_SUSPEND:
@@ -975,11 +975,11 @@
 	p9100_ramdac_write(sc, DAC_CMAP_WRIDX, start);
 
 	for (i=0;i<ncolors;i++) {
-		p9100_ramdac_write(sc, DAC_CMAP_DATA, 
+		p9100_ramdac_write(sc, DAC_CMAP_DATA,
 		    sc->sc_cmap.cm_map[i + start][0]);
-		p9100_ramdac_write(sc, DAC_CMAP_DATA, 
+		p9100_ramdac_write(sc, DAC_CMAP_DATA,
 		    sc->sc_cmap.cm_map[i + start][1]);
-		p9100_ramdac_write(sc, DAC_CMAP_DATA, 
+		p9100_ramdac_write(sc, DAC_CMAP_DATA,
 		    sc->sc_cmap.cm_map[i + start][2]);
 	}
 }
@@ -1049,10 +1049,10 @@
 	struct vcons_screen *scr = ri->ri_hw;
 	struct p9100_softc *sc = scr->scr_cookie;
 	int x, y, wi,he;
-	
+
 	wi = ri->ri_font->fontwidth;
 	he = ri->ri_font->fontheight;
-	
+
 	if (ri->ri_flg & RI_CURSOR) {
 		x = ri->ri_ccol * wi + ri->ri_xorigin;
 		y = ri->ri_crow * he + ri->ri_yorigin;
@@ -1084,14 +1084,14 @@
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	struct p9100_softc *sc = scr->scr_cookie;
-	
+
 	int fg, bg, uc, i;
 	uint8_t *data;
 	int x, y, wi,he;
-			
+
 	wi = ri->ri_font->fontwidth;
 	he = ri->ri_font->fontheight;
-		
+
 	if (!CHAR_IN_FONT(c, ri->ri_font))
 		return;
 	bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
@@ -1102,10 +1102,10 @@
 		p9100_rectfill(sc, x, y, wi, he, bg);
 	} else {
 		uc = c-ri->ri_font->firstchar;
-		data = (uint8_t *)ri->ri_font->data + uc * 
+		data = (uint8_t *)ri->ri_font->data + uc *
 		    ri->ri_fontscale;
 
-		p9100_setup_mono(sc, x, y, wi, 1, fg, bg);		
+		p9100_setup_mono(sc, x, y, wi, 1, fg, bg);
 		for (i = 0; i < he; i++) {
 			p9100_feed_line(sc, ri->ri_font->stride,
 			    data);
@@ -1132,12 +1132,12 @@
 		case WSDISPLAYIO_GTYPE:
 			*(u_int *)data = WSDISPLAY_TYPE_SB_P9100;
 			return 0;
-	
+
 		case FBIOGVIDEO:
 		case WSDISPLAYIO_GVIDEO:
 			*(int *)data = p9100_get_video(sc);
 			return 0;
-			
+
 		case WSDISPLAYIO_SVIDEO:
 		case FBIOSVIDEO:
 			p9100_set_video(sc, *(int *)data);
@@ -1165,7 +1165,7 @@
 					sc->sc_mode = new_mode;
 					if (new_mode == WSDISPLAYIO_MODE_EMUL)
 					{
-						p9100_init_engine(sc);		
+						p9100_init_engine(sc);
 						p9100loadcmap(sc, 0, 256);
 						p9100_clearscreen(sc);
 						vcons_redraw_screen(ms);
@@ -1180,27 +1180,27 @@
 p9100_mmap(void *v, void *vs, off_t offset, int prot)
 {
 	struct vcons_data *vd = v;
-	struct p9100_softc *sc = vd->cookie;	
+	struct p9100_softc *sc = vd->cookie;
 	paddr_t pa;
-	
+
 	/* 'regular' framebuffer mmap()ing */
 	if (offset < sc->sc_fb_psize) {
-		pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0, 
-		    prot, BUS_SPACE_MAP_LINEAR);	
+		pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0,
+		    prot, BUS_SPACE_MAP_LINEAR);
 		return pa;
 	}
 
-	if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr + 
+	if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr +
 	    sc->sc_fb_psize))) {
-		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot, 
-		    BUS_SPACE_MAP_LINEAR);	
+		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
+		    BUS_SPACE_MAP_LINEAR);
 		return pa;
 	}
 
-	if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr + 
+	if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr +
 	    sc->sc_ctl_psize))) {
-		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot, 
-		    BUS_SPACE_MAP_LINEAR);	
+		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
+		    BUS_SPACE_MAP_LINEAR);
 		return pa;
 	}
 
@@ -1213,7 +1213,7 @@
 {
 	struct p9100_softc *sc = cookie;
 	struct rasops_info *ri = &scr->scr_ri;
-	   
+
 	ri->ri_depth = sc->sc_depth << 3;
 	ri->ri_width = sc->sc_width;
 	ri->ri_height = sc->sc_height;
@@ -1314,7 +1314,7 @@
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	int32_t xs, xd, y, width, height;
-	
+
 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
@@ -1329,11 +1329,11 @@
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	int32_t x, y, width, height, bg;
-	
+
 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
 	width = ri->ri_font->fontwidth * ncols;
-	height = ri->ri_font->fontheight;		
+	height = ri->ri_font->fontheight;
 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
 	p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
 }
@@ -1349,7 +1349,7 @@
 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
 	width = ri->ri_emuwidth;
-	height = ri->ri_font->fontheight * nrows;		
+	height = ri->ri_font->fontheight * nrows;
 	p9100_bitblt(scr->scr_cookie, x, ys, x, yd, width, height, ROP_SRC);
 }
 
@@ -1359,7 +1359,7 @@
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	int32_t x, y, width, height, bg;
-	
+
 	if ((row == 0) && (nrows == ri->ri_rows)) {
 		x = y = 0;
 		width = ri->ri_width;
@@ -1384,10 +1384,10 @@
 		bg = WS_DEFAULT_BG;
 	}
 	if (flags & WSATTR_REVERSE) {
-		*attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 | 
+		*attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 |
 		    (flags & 0xff) << 8;
 	} else
-		*attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 | 
+		*attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 |
 		    (flags & 0xff) << 8;
 	return 0;
 }
@@ -1414,7 +1414,7 @@
 static void
 p9100_init_cursor(struct p9100_softc *sc)
 {
-	
+
 	memset(&sc->sc_cursor, 0, sizeof(struct pnozz_cursor));
 	sc->sc_cursor.pc_size.x = 64;
 	sc->sc_cursor.pc_size.y = 64;
@@ -1426,7 +1426,7 @@
 {
 #ifdef PNOZZ_PARANOID
 	int s;
-	
+
 	s = splhigh();	/* just in case... */
 #endif
 	sc->sc_last_offset = 0xffffffff;
@@ -1436,21 +1436,21 @@
 	p9100_ramdac_write(sc, DAC_INDX_HI, 0);
 	p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_CTL);
 	if (sc->sc_cursor.pc_enable) {
-		p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_X11 | 
+		p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_X11 |
 		    DAC_CURSOR_64);
 	} else
 		p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_OFF);
 	/* next two registers - x low, high, y low, high */
 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.x & 0xff);
-	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.x >> 8) & 
+	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.x >> 8) &
 	    0xff);
 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.y & 0xff);
-	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.y >> 8) & 
+	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.y >> 8) &
 	    0xff);
 	/* hotspot */
 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.x & 0xff);
 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.y & 0xff);
-	
+
 #ifdef PNOZZ_PARANOID
 	splx(s);
 #endif
@@ -1461,13 +1461,13 @@
 p9100_setcursorcmap(struct p9100_softc *sc)
 {
 	int i;
-	
+
 #ifdef PNOZZ_PARANOID
 	int s;
 	s = splhigh();	/* just in case... */
 #endif
 	sc->sc_last_offset = 0xffffffff;
-	
+
 	/* set cursor colours */
 	p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
 	p9100_ramdac_write(sc, DAC_INDX_HI, 0);
@@ -1478,7 +1478,7 @@
 		p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.green[i]);
 		p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.blue[i]);
 	}
-	
+
 #ifdef PNOZZ_PARANOID
 	splx(s);
 #endif
@@ -1491,7 +1491,7 @@
 	uint32_t bit, bbit, im, ma;
 	int i, j, k;
 	uint8_t latch1, latch2;
-		
+
 #ifdef PNOZZ_PARANOID
 	int s;
 	s = splhigh();	/* just in case... */
Index: sys/dev/usb/ehci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ehci.c,v
retrieving revision 1.109
diff -u -r1.109 ehci.c
--- sys/dev/usb/ehci.c	14 Apr 2006 17:27:08 -0000	1.109
+++ sys/dev/usb/ehci.c	25 May 2006 11:26:22 -0000
@@ -128,7 +128,7 @@
 };
 
 Static void		ehci_shutdown(void *);
-Static void		ehci_power(int, void *);
+Static void		ehci_power(void *, int);
 
 Static usbd_status	ehci_open(usbd_pipe_handle);
 Static void		ehci_poll(struct usbd_bus *);
@@ -998,7 +998,7 @@
  * are almost suspended anyway.
  */
 void
-ehci_power(int why, void *v)
+ehci_power(void *v, int why)
 {
 	ehci_softc_t *sc = v;
 	u_int32_t cmd, hcr;
@@ -2344,8 +2344,8 @@
 		len -= curlen;
 
 		/*
-		 * Allocate another transfer if there's more data left, 
-		 * or if force last short transfer flag is set and we're 
+		 * Allocate another transfer if there's more data left,
+		 * or if force last short transfer flag is set and we're
 		 * allocating a multiple of the max packet size.
 		 */
 		if (len != 0 ||
@@ -2360,7 +2360,7 @@
 			nextphys = EHCI_NULL;
 		}
 
-		for (i = 0; i * EHCI_PAGE_SIZE < 
+		for (i = 0; i * EHCI_PAGE_SIZE <
 		            curlen + EHCI_PAGE_OFFSET(dataphys); i++) {
 			ehci_physaddr_t a = dataphys + i * EHCI_PAGE_SIZE;
 			if (i != 0) /* use offset only in first buffer */
Index: sys/dev/usb/ohci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ohci.c,v
retrieving revision 1.174
diff -u -r1.174 ohci.c
--- sys/dev/usb/ohci.c	12 May 2006 01:25:00 -0000	1.174
+++ sys/dev/usb/ohci.c	25 May 2006 11:26:23 -0000
@@ -137,7 +137,7 @@
 			    ohci_soft_td_t *, ohci_soft_td_t **);
 
 Static void		ohci_shutdown(void *v);
-Static void		ohci_power(int, void *);
+Static void		ohci_power(void *, int);
 Static usbd_status	ohci_open(usbd_pipe_handle);
 Static void		ohci_poll(struct usbd_bus *);
 Static void		ohci_softintr(void *);
@@ -1025,7 +1025,7 @@
  * are almost suspended anyway.
  */
 void
-ohci_power(int why, void *v)
+ohci_power(void *v, int why)
 {
 	ohci_softc_t *sc = v;
 	u_int32_t ctl;
Index: sys/dev/usb/uhci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uhci.c,v
retrieving revision 1.196
diff -u -r1.196 uhci.c
--- sys/dev/usb/uhci.c	12 May 2006 01:25:00 -0000	1.196
+++ sys/dev/usb/uhci.c	25 May 2006 11:26:24 -0000
@@ -166,7 +166,7 @@
 Static usbd_status	uhci_portreset(uhci_softc_t*, int);
 Static void		uhci_reset(uhci_softc_t *);
 Static void		uhci_shutdown(void *v);
-Static void		uhci_power(int, void *);
+Static void		uhci_power(void *, int);
 Static usbd_status	uhci_run(uhci_softc_t *, int run);
 Static uhci_soft_td_t  *uhci_alloc_std(uhci_softc_t *);
 Static void		uhci_free_std(uhci_softc_t *, uhci_soft_td_t *);
@@ -741,7 +741,7 @@
  * are almost suspended anyway.
  */
 void
-uhci_power(int why, void *v)
+uhci_power(void *v, int why)
 {
 	uhci_softc_t *sc = v;
 	int cmd;
Index: sys/kern/init_main.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_main.c,v
retrieving revision 1.266
diff -u -r1.266 init_main.c
--- sys/kern/init_main.c	14 May 2006 21:15:11 -0000	1.266
+++ sys/kern/init_main.c	25 May 2006 11:26:24 -0000
@@ -111,6 +111,7 @@
 #include <sys/user.h>
 #include <sys/sysctl.h>
 #include <sys/event.h>
+#include <sys/eventhandler.h>
 #include <sys/mbuf.h>
 #ifdef FAST_IPSEC
 #include <netipsec/ipsec.h>
@@ -220,6 +221,9 @@
 
 	KERNEL_LOCK_INIT();
 
+	/* init the eventhandler queue early so subsystems can set up hooks */
+	eventhandler_init();
+
 	uvm_init();
 
 	/* Do machine-dependent initialization. */
Index: sys/kern/kern_sig.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_sig.c,v
retrieving revision 1.220
diff -u -r1.220 kern_sig.c
--- sys/kern/kern_sig.c	14 May 2006 21:15:11 -0000	1.220
+++ sys/kern/kern_sig.c	25 May 2006 11:26:25 -0000
@@ -84,7 +84,7 @@
 #include <uvm/uvm_extern.h>
 
 static int	build_corename(struct proc *, char *, const char *, size_t);
-static void	ksiginfo_exithook(struct proc *, void *);
+static void	ksiginfo_exithook(void *, struct proc *);
 static void	ksiginfo_put(struct proc *, const ksiginfo_t *);
 static ksiginfo_t *ksiginfo_get(struct proc *, int);
 static void	kpsignal2(struct proc *, const ksiginfo_t *, int);
@@ -199,7 +199,7 @@
  * free all pending ksiginfo on exit
  */
 static void
-ksiginfo_exithook(struct proc *p, void *v)
+ksiginfo_exithook(void *v, struct proc *p)
 {
 	int s;
 
@@ -363,7 +363,7 @@
 					p->p_flag |= P_CLDSIGIGN;
 			} else
 				p->p_flag &= ~P_CLDSIGIGN;
-				
+
 		}
 		if ((nsa->sa_flags & SA_NODEFER) == 0)
 			sigaddset(&SIGACTION_PS(ps, signum).sa_mask, signum);
Index: sys/kern/kern_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_subr.c,v
retrieving revision 1.135
diff -u -r1.135 kern_subr.c
--- sys/kern/kern_subr.c	28 Mar 2006 17:38:39 -0000	1.135
+++ sys/kern/kern_subr.c	25 May 2006 11:26:25 -0000
@@ -108,6 +108,7 @@
 #include <sys/ktrace.h>
 #include <sys/ptrace.h>
 #include <sys/fcntl.h>
+#include <sys/eventhandler.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -115,21 +116,13 @@
 
 #include <net/if.h>
 
+static int mountroot_mask(void *arg);
+
 /* XXX these should eventually move to subr_autoconf.c */
 static struct device *finddevice(const char *);
 static struct device *getdisk(char *, int, int, dev_t *, int);
 static struct device *parsedisk(char *, int, int, dev_t *);
 
-/*
- * A generic linear hook.
- */
-struct hook_desc {
-	LIST_ENTRY(hook_desc) hk_list;
-	void	(*hk_fn)(void *);
-	void	*hk_arg;
-};
-typedef LIST_HEAD(, hook_desc) hook_list_t;
-
 MALLOC_DEFINE(M_IOV, "iov", "large iov's");
 
 void
@@ -442,62 +435,6 @@
 }
 
 
-static void *
-hook_establish(hook_list_t *list, void (*fn)(void *), void *arg)
-{
-	struct hook_desc *hd;
-
-	hd = malloc(sizeof(*hd), M_DEVBUF, M_NOWAIT);
-	if (hd == NULL)
-		return (NULL);
-
-	hd->hk_fn = fn;
-	hd->hk_arg = arg;
-	LIST_INSERT_HEAD(list, hd, hk_list);
-
-	return (hd);
-}
-
-static void
-hook_disestablish(hook_list_t *list, void *vhook)
-{
-#ifdef DIAGNOSTIC
-	struct hook_desc *hd;
-
-	LIST_FOREACH(hd, list, hk_list) {
-                if (hd == vhook)
-			break;
-	}
-
-	if (hd == NULL)
-		panic("hook_disestablish: hook %p not established", vhook);
-#endif
-	LIST_REMOVE((struct hook_desc *)vhook, hk_list);
-	free(vhook, M_DEVBUF);
-}
-
-static void
-hook_destroy(hook_list_t *list)
-{
-	struct hook_desc *hd;
-
-	while ((hd = LIST_FIRST(list)) != NULL) {
-		LIST_REMOVE(hd, hk_list);
-		free(hd, M_DEVBUF);
-	}
-}
-
-static void
-hook_proc_run(hook_list_t *list, struct proc *p)
-{
-	struct hook_desc *hd;
-
-	for (hd = LIST_FIRST(list); hd != NULL; hd = LIST_NEXT(hd, hk_list)) {
-		((void (*)(struct proc *, void *))*hd->hk_fn)(p,
-		    hd->hk_arg);
-	}
-}
-
 /*
  * "Shutdown hook" types, functions, and variables.
  *
@@ -509,18 +446,22 @@
  * it won't be run again.
  */
 
-static hook_list_t shutdownhook_list;
 
-void *
-shutdownhook_establish(void (*fn)(void *), void *arg)
+eventhandler_tag
+shutdownhook_establish(shutdown_fn fn, void *arg)
 {
-	return hook_establish(&shutdownhook_list, fn, arg);
+	eventhandler_tag tag;
+
+	tag = EVENTHANDLER_REGISTER(shutdown, fn, arg,
+				    EVENTHANDLER_PRI_ANY);
+	EVENTHANDLER_FLAGS(shutdown, EHL_ONCE);
+	return tag;
 }
 
 void
-shutdownhook_disestablish(void *vhook)
+shutdownhook_disestablish(eventhandler_tag tag)
 {
-	hook_disestablish(&shutdownhook_list, vhook);
+	EVENTHANDLER_DEREGISTER(shutdown, tag);
 }
 
 /*
@@ -534,73 +475,62 @@
 void
 doshutdownhooks(void)
 {
-	struct hook_desc *dp;
-
-	while ((dp = LIST_FIRST(&shutdownhook_list)) != NULL) {
-		LIST_REMOVE(dp, hk_list);
-		(*dp->hk_fn)(dp->hk_arg);
-#if 0
-		/*
-		 * Don't bother freeing the hook structure,, since we may
-		 * be rebooting because of a memory corruption problem,
-		 * and this might only make things worse.  It doesn't
-		 * matter, anyway, since the system is just about to
-		 * reboot.
-		 */
-		free(dp, M_DEVBUF);
-#endif
-	}
+	EVENTHANDLER_INVOKE(shutdown);
 }
 
 /*
  * "Mountroot hook" types, functions, and variables.
  */
 
-static hook_list_t mountroothook_list;
-
-void *
-mountroothook_establish(void (*fn)(struct device *), struct device *dev)
+eventhandler_tag
+mountroothook_establish(mountroot_fn fn, struct device *dev)
 {
-	return hook_establish(&mountroothook_list, (void (*)(void *))fn, dev);
+	eventhandler_tag tag;
+
+	tag = EVENTHANDLER_REGISTER(mountroot_list, fn, (void *) dev,
+				    EVENTHANDLER_PRI_ANY);
+	EVENTHANDLER_MASK_FN(mountroot_list, mountroot_mask);
+	return tag;
 }
 
 void
-mountroothook_disestablish(void *vhook)
+mountroothook_disestablish(eventhandler_tag tag)
 {
-	hook_disestablish(&mountroothook_list, vhook);
+	EVENTHANDLER_DEREGISTER(mountroot_list, tag);
 }
 
 void
 mountroothook_destroy(void)
 {
-	hook_destroy(&mountroothook_list);
+	EVENTHANDLER_DEREGISTER(mountroot_list, NULL);
 }
 
 void
 domountroothook(void)
 {
-	struct hook_desc *hd;
-
-	LIST_FOREACH(hd, &mountroothook_list, hk_list) {
-		if (hd->hk_arg == (void *)root_device) {
-			(*hd->hk_fn)(hd->hk_arg);
-			return;
-		}
-	}
+	EVENTHANDLER_INVOKE(mountroot_list);
 }
 
-static hook_list_t exechook_list;
+static int
+mountroot_mask(void *arg)
+{
+	if (arg == (void *)root_device)
+		return 1;
+	else
+		return 0;
+}
 
-void *
-exechook_establish(void (*fn)(struct proc *, void *), void *arg)
+eventhandler_tag
+exechook_establish(execlist_fn fn, void *arg)
 {
-	return hook_establish(&exechook_list, (void (*)(void *))fn, arg);
+	return EVENTHANDLER_REGISTER(process_exec, (void (*)(void *)) fn, arg,
+				     EVENTHANDLER_PRI_ANY);
 }
 
 void
-exechook_disestablish(void *vhook)
+exechook_disestablish(eventhandler_tag tag)
 {
-	hook_disestablish(&exechook_list, vhook);
+	EVENTHANDLER_DEREGISTER(process_exec, tag);
 }
 
 /*
@@ -609,21 +539,20 @@
 void
 doexechooks(struct proc *p)
 {
-	hook_proc_run(&exechook_list, p);
+	EVENTHANDLER_INVOKE(process_exec, p);
 }
 
-static hook_list_t exithook_list;
-
-void *
-exithook_establish(void (*fn)(struct proc *, void *), void *arg)
+eventhandler_tag
+exithook_establish(exitlist_fn fn, void *arg)
 {
-	return hook_establish(&exithook_list, (void (*)(void *))fn, arg);
+	return EVENTHANDLER_REGISTER(process_exit, (void (*)(void *)) fn, arg,
+				     EVENTHANDLER_PRI_ANY);
 }
 
 void
-exithook_disestablish(void *vhook)
+exithook_disestablish(eventhandler_tag tag)
 {
-	hook_disestablish(&exithook_list, vhook);
+	EVENTHANDLER_DEREGISTER(process_exit, tag);
 }
 
 /*
@@ -632,21 +561,20 @@
 void
 doexithooks(struct proc *p)
 {
-	hook_proc_run(&exithook_list, p);
+	EVENTHANDLER_INVOKE(process_exit, p);
 }
 
-static hook_list_t forkhook_list;
-
-void *
-forkhook_establish(void (*fn)(struct proc *, struct proc *))
+eventhandler_tag
+forkhook_establish(forklist_fn fn)
 {
-	return hook_establish(&forkhook_list, (void (*)(void *))fn, NULL);
+	return EVENTHANDLER_REGISTER(process_fork, (void (*)(void *)) fn, NULL,
+				     EVENTHANDLER_PRI_ANY);
 }
 
 void
-forkhook_disestablish(void *vhook)
+forkhook_disestablish(eventhandler_tag tag)
 {
-	hook_disestablish(&forkhook_list, vhook);
+	EVENTHANDLER_DEREGISTER(process_fork, tag);
 }
 
 /*
@@ -655,63 +583,28 @@
 void
 doforkhooks(struct proc *p2, struct proc *p1)
 {
-	struct hook_desc *hd;
-
-	LIST_FOREACH(hd, &forkhook_list, hk_list) {
-		((void (*)(struct proc *, struct proc *))*hd->hk_fn)
-		    (p2, p1);
-	}
+	EVENTHANDLER_INVOKE(process_fork, p2, p1);
 }
 
 /*
  * "Power hook" types, functions, and variables.
  * The list of power hooks is kept ordered with the last registered hook
- * first.
+ * first. XXXX eventhandler is the reverse of this!
  * When running the hooks on power down the hooks are called in reverse
  * registration order, when powering up in registration order.
  */
-struct powerhook_desc {
-	CIRCLEQ_ENTRY(powerhook_desc) sfd_list;
-	void	(*sfd_fn)(int, void *);
-	void	*sfd_arg;
-};
 
-static CIRCLEQ_HEAD(, powerhook_desc) powerhook_list =
-    CIRCLEQ_HEAD_INITIALIZER(powerhook_list);
-
-void *
-powerhook_establish(void (*fn)(int, void *), void *arg)
+eventhandler_tag
+powerhook_establish(powerlist_fn fn, void *arg)
 {
-	struct powerhook_desc *ndp;
-
-	ndp = (struct powerhook_desc *)
-	    malloc(sizeof(*ndp), M_DEVBUF, M_NOWAIT);
-	if (ndp == NULL)
-		return (NULL);
-
-	ndp->sfd_fn = fn;
-	ndp->sfd_arg = arg;
-	CIRCLEQ_INSERT_HEAD(&powerhook_list, ndp, sfd_list);
-
-	return (ndp);
+	return EVENTHANDLER_REGISTER(power_list, (void (*)(void *)) fn, arg,
+				     EVENTHANDLER_PRI_ANY);
 }
 
 void
-powerhook_disestablish(void *vhook)
+powerhook_disestablish(eventhandler_tag tag)
 {
-#ifdef DIAGNOSTIC
-	struct powerhook_desc *dp;
-
-	CIRCLEQ_FOREACH(dp, &powerhook_list, sfd_list)
-                if (dp == vhook)
-			goto found;
-	panic("powerhook_disestablish: hook %p not established", vhook);
- found:
-#endif
-
-	CIRCLEQ_REMOVE(&powerhook_list, (struct powerhook_desc *)vhook,
-	    sfd_list);
-	free(vhook, M_DEVBUF);
+	EVENTHANDLER_DEREGISTER(power_list, tag);
 }
 
 /*
@@ -720,16 +613,10 @@
 void
 dopowerhooks(int why)
 {
-	struct powerhook_desc *dp;
-
 	if (why == PWR_RESUME || why == PWR_SOFTRESUME) {
-		CIRCLEQ_FOREACH_REVERSE(dp, &powerhook_list, sfd_list) {
-			(*dp->sfd_fn)(why, dp->sfd_arg);
-		}
+		EVENTHANDLER_INVOKE(power_list, why);
 	} else {
-		CIRCLEQ_FOREACH(dp, &powerhook_list, sfd_list) {
-			(*dp->sfd_fn)(why, dp->sfd_arg);
-		}
+		EVENTHANDLER_INVOKE_REVERSE(power_list, why);
 	}
 }
 
@@ -1400,7 +1287,7 @@
 		KERNEL_PROC_UNLOCK(l);
 	}
 #endif /* KTRACE */
-	
+
 	if ((p->p_flag & (P_SYSCALL|P_TRACED)) == (P_SYSCALL|P_TRACED))
 		process_stoptrace(l);
 
Index: sys/kern/sysv_sem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sysv_sem.c,v
retrieving revision 1.61
diff -u -r1.61 sysv_sem.c
--- sys/kern/sysv_sem.c	14 May 2006 21:15:11 -0000	1.61
+++ sys/kern/sysv_sem.c	25 May 2006 11:26:25 -0000
@@ -819,7 +819,7 @@
  */
 /*ARGSUSED*/
 void
-semexit(struct proc *p, void *v)
+semexit(void *v, struct proc *p)
 {
 	struct sem_undo *suptr;
 	struct sem_undo **supptr;
Index: sys/kern/uipc_sem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_sem.c,v
retrieving revision 1.14
diff -u -r1.14 uipc_sem.c
--- sys/kern/uipc_sem.c	14 May 2006 21:15:12 -0000	1.14
+++ sys/kern/uipc_sem.c	25 May 2006 11:26:26 -0000
@@ -752,8 +752,9 @@
 	return (0);
 }
 
+/* ARGS_USED */
 static void
-ksem_forkhook(struct proc *p2, struct proc *p1)
+ksem_forkhook(void *arg, struct proc *p2, struct proc *p1)
 {
 	struct ksem_proc *kp1, *kp2;
 	struct ksem_ref *ksr, *ksr1;
@@ -782,7 +783,7 @@
 }
 
 static void
-ksem_exithook(struct proc *p, void *arg)
+ksem_exithook(void *arg, struct proc *p)
 {
 	struct ksem_proc *kp;
 	struct ksem_ref *ksr;
Index: sys/miscfs/procfs/procfs.h
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs.h,v
retrieving revision 1.59
diff -u -r1.59 procfs.h
--- sys/miscfs/procfs/procfs.h	11 Dec 2005 12:24:51 -0000	1.59
+++ sys/miscfs/procfs/procfs.h	25 May 2006 11:26:26 -0000
@@ -207,7 +207,7 @@
 int procfs_domounts(struct lwp *, struct proc *, struct pfsnode *,
     struct uio *);
 
-void procfs_revoke_vnodes(struct proc *, void *);
+void procfs_revoke_vnodes(void *, struct proc *);
 void procfs_hashinit(void);
 void procfs_hashreinit(void);
 void procfs_hashdone(void);
Index: sys/miscfs/procfs/procfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_subr.c,v
retrieving revision 1.68
diff -u -r1.68 procfs_subr.c
--- sys/miscfs/procfs/procfs_subr.c	1 Mar 2006 12:38:32 -0000	1.68
+++ sys/miscfs/procfs/procfs_subr.c	25 May 2006 11:26:26 -0000
@@ -548,9 +548,7 @@
 }
 
 void
-procfs_revoke_vnodes(p, arg)
-	struct proc *p;
-	void *arg;
+procfs_revoke_vnodes(void *arg, struct proc *p)
 {
 	struct pfsnode *pfs, *pnext;
 	struct vnode *vp;
Index: sys/nfs/nfs_socket.c
===================================================================
RCS file: /cvsroot/src/sys/nfs/nfs_socket.c,v
retrieving revision 1.132
diff -u -r1.132 nfs_socket.c
--- sys/nfs/nfs_socket.c	19 May 2006 13:53:11 -0000	1.132
+++ sys/nfs/nfs_socket.c	25 May 2006 11:26:27 -0000
@@ -1757,9 +1757,7 @@
 
 /*ARGSUSED*/
 void
-nfs_exit(p, v)
-	struct proc *p;
-	void *v;
+nfs_exit(void *v, struct proc *p)
 {
 	struct nfsreq *rp;
 	int s = splsoftnet();
@@ -2638,14 +2636,14 @@
 	nfsdreq_free(nd);
 
 	simple_lock(&slp->ns_lock);
-	KASSERT((slp->ns_flag & SLP_SENDING) != 0); 
+	KASSERT((slp->ns_flag & SLP_SENDING) != 0);
 	nd = SIMPLEQ_FIRST(&slp->ns_sendq);
 	if (nd != NULL) {
 		SIMPLEQ_REMOVE_HEAD(&slp->ns_sendq, nd_sendq);
 		simple_unlock(&slp->ns_lock);
 		goto again;
 	}
-	slp->ns_flag &= ~SLP_SENDING; 
+	slp->ns_flag &= ~SLP_SENDING;
 	simple_unlock(&slp->ns_lock);
 
 	return error;
Index: sys/nfs/nfs_var.h
===================================================================
RCS file: /cvsroot/src/sys/nfs/nfs_var.h,v
retrieving revision 1.61
diff -u -r1.61 nfs_var.h
--- sys/nfs/nfs_var.h	19 May 2006 13:53:11 -0000	1.61
+++ sys/nfs/nfs_var.h	25 May 2006 11:26:27 -0000
@@ -217,7 +217,7 @@
 void nfs_timer(void *);
 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct lwp *);
 int nfs_sndlock(int *, struct nfsreq *);
-void nfs_exit(struct proc *, void *);
+void nfs_exit(void *, struct proc *);
 void nfs_sndunlock(int *);
 int nfs_rcvlock(struct nfsreq *);
 void nfs_rcvunlock(struct nfsmount *);
Index: sys/sys/sem.h
===================================================================
RCS file: /cvsroot/src/sys/sys/sem.h,v
retrieving revision 1.21
diff -u -r1.21 sem.h
--- sys/sys/sem.h	11 Dec 2005 12:25:21 -0000	1.21
+++ sys/sys/sem.h	25 May 2006 11:26:27 -0000
@@ -225,7 +225,7 @@
 __END_DECLS
 #else
 void	seminit(void);
-void	semexit(struct proc *, void *);
+void	semexit(void *, struct proc *);
 
 int	semctl1(struct proc *, int, int, int, void *, register_t *);
 #endif /* !_KERNEL */
Index: sys/sys/systm.h
===================================================================
RCS file: /cvsroot/src/sys/sys/systm.h,v
retrieving revision 1.186
diff -u -r1.186 systm.h
--- sys/sys/systm.h	7 Mar 2006 13:18:20 -0000	1.186
+++ sys/sys/systm.h	25 May 2006 11:26:28 -0000
@@ -77,6 +77,7 @@
 
 #ifdef _KERNEL
 #include <sys/types.h>
+#include <sys/eventhandler.h>
 #endif
 
 struct clockframe;
@@ -303,15 +304,15 @@
  * Shutdown hooks.  Functions to be run with all interrupts disabled
  * immediately before the system is halted or rebooted.
  */
-void	*shutdownhook_establish(void (*)(void *), void *);
-void	shutdownhook_disestablish(void *);
+eventhandler_tag	shutdownhook_establish(shutdown_fn, void *);
+void	shutdownhook_disestablish(eventhandler_tag);
 void	doshutdownhooks(void);
 
 /*
  * Power management hooks.
  */
-void	*powerhook_establish(void (*)(int, void *), void *);
-void	powerhook_disestablish(void *);
+eventhandler_tag	powerhook_establish(powerlist_fn, void *);
+void	powerhook_disestablish(eventhandler_tag);
 void	dopowerhooks(int);
 #define PWR_RESUME	0
 #define PWR_SUSPEND	1
@@ -326,8 +327,8 @@
  * selected as the root device.
  */
 extern int (*mountroot)(void);
-void	*mountroothook_establish(void (*)(struct device *), struct device *);
-void	mountroothook_disestablish(void *);
+eventhandler_tag	mountroothook_establish(mountroot_fn, struct device *);
+void	mountroothook_disestablish(eventhandler_tag);
 void	mountroothook_destroy(void);
 void	domountroothook(void);
 
@@ -335,23 +336,23 @@
  * Exec hooks. Subsystems may want to do cleanup when a process
  * execs.
  */
-void	*exechook_establish(void (*)(struct proc *, void *), void *);
-void	exechook_disestablish(void *);
+eventhandler_tag	exechook_establish(execlist_fn, void *);
+void	exechook_disestablish(eventhandler_tag);
 void	doexechooks(struct proc *);
 
 /*
  * Exit hooks. Subsystems may want to do cleanup when a process exits.
  */
-void	*exithook_establish(void (*)(struct proc *, void *), void *);
-void	exithook_disestablish(void *);
+eventhandler_tag	exithook_establish(exitlist_fn, void *);
+void	exithook_disestablish(eventhandler_tag);
 void	doexithooks(struct proc *);
 
 /*
  * Fork hooks.  Subsystems may want to do special processing when a process
  * forks.
  */
-void	*forkhook_establish(void (*)(struct proc *, struct proc *));
-void	forkhook_disestablish(void *);
+eventhandler_tag	forkhook_establish(forklist_fn);
+void	forkhook_disestablish(eventhandler_tag);
 void	doforkhooks(struct proc *, struct proc *);
 
 /*

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="eventhandler.h"

/*-
 * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: /repoman/r/ncvs/src/sys/sys/eventhandler.h,v 1.34 2006/04/21 09:25:40 ps Exp $
 */

#ifndef SYS_EVENTHANDLER_H
#define SYS_EVENTHANDLER_H

#include <sys/lock.h>
#include <sys/queue.h>

struct eventhandler_entry {
	TAILQ_ENTRY(eventhandler_entry)	ee_link;
	int				ee_priority;
#define	EHE_DEAD_PRIORITY	(-1)
	void				*ee_arg;
};

struct eventhandler_list {
	char				*el_name;
	int				el_flags;
#define EHL_INITTED	(1<<0)
#define EHL_ONCE	(1<<1)
	u_int				el_runcount;
	struct lock			el_lock;
	int (*el_mask_fn)(void *);
	TAILQ_ENTRY(eventhandler_list)	el_link;
	TAILQ_HEAD(eventhandler_entries_head ,eventhandler_entry)	el_entries;
};

typedef struct eventhandler_entry	*eventhandler_tag;

#define	EHL_LOCK(p)		lockmgr(&(p)->el_lock, LK_EXCLUSIVE, NULL)
#define	EHL_UNLOCK(p)		lockmgr(&(p)->el_lock, LK_RELEASE, NULL)
#define	EHL_LOCK_ASSERT(p,x)	KASSERT(lockstatus(&(p)->el_lock) == (x));

/*#define EVENTHANDLER_DEBUG	1 */
#ifdef EVENTHANDLER_DEBUG
extern int eventhandlerdebug;
#define EH_PRINTF(x)	if (eventhandlerdebug) printf (x)
#define EH_PRINTFN(n,x)	if (eventhandlerdebug>(n)) printf x
#else
#define EH_PRINTF(x)
#define EH_PRINTFN(n,x, ...)
#endif

/*
 * Macro to invoke the handlers for a given event.  The list must be
 * exclusively locked on entry, it will be unlocked on exit.
 */
#define _EVENTHANDLER_INVOKE(name, list, ...) do {			\
	struct eventhandler_entry *_ep;					\
	struct eventhandler_entry_ ## name *_t;				\
									\
	KASSERT((list)->el_flags & EHL_INITTED);			\
	EHL_LOCK_ASSERT((list), LK_EXCLUSIVE);				\
	(list)->el_runcount++;						\
	KASSERT((list)->el_runcount > 0);				\
	EH_PRINTF("eventhandler_invoke(\"" __STRING(name) "\")\n");	\
	TAILQ_FOREACH(_ep, &((list)->el_entries), ee_link) {		\
		if (_ep->ee_priority != EHE_DEAD_PRIORITY) {		\
			if (((list)->el_flags & EHL_ONCE) == EHL_ONCE) { \
				_ep->ee_priority = EHE_DEAD_PRIORITY;	\
			}						\
			EHL_UNLOCK((list));				\
			if (((list)->el_mask_fn == NULL) ||		\
			    (((list)->el_mask_fn != NULL) && 		\
			     ((list)->el_mask_fn(_ep->ee_arg) != 0))) {	\
				_t = (struct eventhandler_entry_ ## name *)_ep;	\
				EH_PRINTFN(1, ("eventhandler_invoke: executing %p\n", \
 					  (void *)_t->eh_func));	\
				_t->eh_func(_ep->ee_arg , ## __VA_ARGS__); \
			}						\
			EHL_LOCK((list));				\
		}							\
	}								\
	KASSERT((list)->el_runcount > 0);				\
	(list)->el_runcount--;						\
	if ((list)->el_runcount == 0)					\
		eventhandler_prune_list(list);				\
	EHL_UNLOCK((list));						\
} while (0)

/*
 * Macro to invoke the handlers for a given event, the handler list is
 * traversed in reverse order.  The list must be exclusively locked on
 * entry, it will be unlocked on exit.
 */
#define _EVENTHANDLER_INVOKE_REVERSE(name, list, ...) do {		\
	struct eventhandler_entry *_ep;					\
	struct eventhandler_entry_ ## name *_t;				\
									\
	KASSERT((list)->el_flags & EHL_INITTED);			\
	EHL_LOCK_ASSERT((list), LK_EXCLUSIVE);				\
	(list)->el_runcount++;						\
	KASSERT((list)->el_runcount > 0);				\
	EH_PRINTF("eventhandler_invoke(\"" __STRING(name) "\")\n");	\
	TAILQ_FOREACH_REVERSE(_ep, &((list)->el_entries), 		\
				eventhandler_entries_head, ee_link) {	\
		if (_ep->ee_priority != EHE_DEAD_PRIORITY) {		\
			if (((list)->el_flags & EHL_ONCE) == EHL_ONCE) { \
				_ep->ee_priority = EHE_DEAD_PRIORITY;	\
			}						\
			EHL_UNLOCK((list));				\
			if (((list)->el_mask_fn == NULL) ||		\
			    (((list)->el_mask_fn != NULL) && 		\
			     ((list)->el_mask_fn(_ep->ee_arg) != 0))) {	\
				_t = (struct eventhandler_entry_ ## name *)_ep;	\
				EH_PRINTFN(1, ("eventhandler_invoke: executing %p\n", \
 					   (void *)_t->eh_func));	\
				_t->eh_func(_ep->ee_arg , ## __VA_ARGS__); \
			}						\
			EHL_LOCK((list));				\
		}							\
	}								\
	KASSERT((list)->el_runcount > 0);				\
	(list)->el_runcount--;						\
	if ((list)->el_runcount == 0)					\
		eventhandler_prune_list(list);				\
	EHL_UNLOCK((list));						\
} while (0)

/*
 * Macro to invoke the handlers for a given event.
 */
#define _EVENTHANDLER_FAST_INVOKE(name, list, ...) do {			\
	struct eventhandler_entry *_ep;					\
	struct eventhandler_entry_ ## name *_t;				\
									\
	TAILQ_FOREACH(_ep, &((list)->el_entries), ee_link) {		\
		_t = (struct eventhandler_entry_ ## name *)_ep;		\
		_t->eh_func(_ep->ee_arg , ## __VA_ARGS__);		\
	}								\
	EHL_UNLOCK((list));						\
} while (0)

/*
 * Macro to invoke the handlers for a given event, the handler list is
 * traversed in reverse order.
 */
#define _EVENTHANDLER_FAST_INVOKE_REVERSE(name, list, ...) do {		\
	struct eventhandler_entry *_ep;					\
	struct eventhandler_entry_ ## name *_t;				\
									\
	TAILQ_FOREACH_REVERSE(_ep, &((list)->el_entries), list, ee_link) { \
		_t = (struct eventhandler_entry_ ## name *)_ep;		\
		_t->eh_func(_ep->ee_arg , ## __VA_ARGS__);		\
	}								\
	EHL_UNLOCK((list));						\
} while (0)

/*
 * Handlers need to be declared, but do not need to be defined. The
 * declaration must be in scope wherever the handler is to be invoked.
 */
#define EVENTHANDLER_DECLARE(name, type)				\
struct eventhandler_entry_ ## name 					\
{									\
	struct eventhandler_entry	ee;				\
	type				eh_func;			\
};									\

#define EVENTHANDLER_INVOKE(name, ...)					\
do {									\
	struct eventhandler_list *_el;					\
									\
	if ((_el = eventhandler_find_list(#name)) != NULL) 		\
		_EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__);	\
} while (0)

#define EVENTHANDLER_INVOKE_REVERSE(name, ...)				\
do {									\
	struct eventhandler_list *_el;					\
									\
	if ((_el = eventhandler_find_list(#name)) != NULL) 		\
		_EVENTHANDLER_INVOKE_REVERSE(name, _el , ## __VA_ARGS__); \
} while (0)

#define EVENTHANDLER_REGISTER(name, func, arg, priority)		\
	eventhandler_register(NULL, #name, func, arg, priority)

#define EVENTHANDLER_DEREGISTER(name, tag) 				\
do {									\
	struct eventhandler_list *_el;					\
									\
	if ((_el = eventhandler_find_list(#name)) != NULL)		\
		eventhandler_deregister(_el, tag);			\
} while(0)

#define EVENTHANDLER_FLAGS(name, flags) 				\
do {									\
	struct eventhandler_list *_el;					\
									\
	if ((_el = eventhandler_find_list(#name)) != NULL)		\
		eventhandler_set_list_flags(_el, flags);		\
} while(0)

#define EVENTHANDLER_MASK_FN(name, mask_fn) 				\
do {									\
	struct eventhandler_list *_el;					\
									\
	if ((_el = eventhandler_find_list(#name)) != NULL)		\
		eventhandler_set_mask(_el, mask_fn);			\
} while(0)

void eventhandler_init(void);
eventhandler_tag eventhandler_register(struct eventhandler_list *,
				       const char *, void *, void *, int);
void	eventhandler_deregister(struct eventhandler_list *,
				eventhandler_tag);
struct eventhandler_list *eventhandler_find_list(const char *);
void	eventhandler_prune_list(struct eventhandler_list *);
void	eventhandler_set_list_flags(struct eventhandler_list *, int);
void	eventhandler_set_mask(struct eventhandler_list *, int (*)(void *));

/*
 * Standard system event queues.
 */

/* Generic priority levels */
#define	EVENTHANDLER_PRI_FIRST	0
#define	EVENTHANDLER_PRI_ANY	10000
#define	EVENTHANDLER_PRI_LAST	20000

/* Shutdown events */
typedef void (*shutdown_fn)(void *);

EVENTHANDLER_DECLARE(shutdown, shutdown_fn);

/* Mount root event */
struct device;

typedef void (*mountroot_fn)(struct device *);

EVENTHANDLER_DECLARE(mountroot_list, mountroot_fn);

/*
 * Process events
 */
struct proc;

typedef void (*exitlist_fn)(void *, struct proc *);
typedef void (*forklist_fn)(void *, struct proc *, struct proc *);
typedef void (*execlist_fn)(void *, struct proc *);

EVENTHANDLER_DECLARE(process_exit, exitlist_fn);
EVENTHANDLER_DECLARE(process_fork, forklist_fn);
EVENTHANDLER_DECLARE(process_exec, execlist_fn);

typedef void (*powerlist_fn)(void *, int);
EVENTHANDLER_DECLARE(power_list, powerlist_fn);

#endif /* SYS_EVENTHANDLER_H */

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="subr_eventhandler.c"

/*-
 * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
#ifdef __FreeBSD__
__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/kern/subr_eventhandler.c,v 1.23 2005/02/23 19:32:29 sam Exp $");
#endif

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/eventhandler.h>

#ifdef EVENTHANDLER_DEBUG
int	eventhandlerdebug = EVENTHANDLER_DEBUG;
#endif

static MALLOC_DEFINE(M_EVENTHANDLER, "eventhandler", "Event handler records");

/* List of eventhandler lists */
static TAILQ_HEAD(, eventhandler_list)	eventhandler_lists;
static int				eventhandler_lists_initted = 0;
static struct lock			eventhandler_lock;

struct eventhandler_entry_generic
{
    struct eventhandler_entry	ee;
    void			(* func)(void);
};

static struct eventhandler_list *_eventhandler_find_list(const char *name);

/*
 * Initialize the eventhandler lock and list.
 */
void
eventhandler_init(void)
{
    TAILQ_INIT(&eventhandler_lists);
    lockinit(&eventhandler_lock, PWAIT, "eventhandler", 0, 0);
    eventhandler_lists_initted = 1;
}

/*
 * Insertion is O(n) due to the priority scan, but optimises to O(1)
 * if all priorities are identical.
 */
eventhandler_tag
eventhandler_register(struct eventhandler_list *list, const char *name,
		      void *func, void *arg, int priority)
{
    struct eventhandler_list		*new_list;
    struct eventhandler_entry_generic	*eg;
    struct eventhandler_entry		*ep;

    KASSERT(eventhandler_lists_initted);

    /* lock the eventhandler lists */
    lockmgr(&eventhandler_lock, LK_EXCLUSIVE, NULL);

    /* Do we need to find/create the (slow) list? */
    if (list == NULL) {
	/* look for a matching, existing list */
	list = _eventhandler_find_list(name);

	/* Do we need to create the list? */
	if (list == NULL) {
	    lockmgr(&eventhandler_lock, LK_RELEASE, NULL);

	    new_list = malloc(sizeof(struct eventhandler_list) +
		strlen(name) + 1, M_EVENTHANDLER, M_WAITOK);

	    /* If someone else created it already, then use that one. */
	    lockmgr(&eventhandler_lock, LK_EXCLUSIVE, NULL);
	    list = _eventhandler_find_list(name);
	    if (list != NULL) {
		free(new_list, M_EVENTHANDLER);
	    } else {
		EH_PRINTFN(2, ("%s: creating list \"%s\"\n", __func__, name));
		list = new_list;
		list->el_flags = 0;
		list->el_runcount = 0;
		list->el_mask_fn = 0;
		lockinit(&list->el_lock, PWAIT, name, 0, 0);
		list->el_name = (char *)list
			+ sizeof(struct eventhandler_list);
		strcpy(list->el_name, name);
		TAILQ_INSERT_HEAD(&eventhandler_lists, list, el_link);
	    }
	}
    }
    if (!(list->el_flags & EHL_INITTED)) {
	TAILQ_INIT(&list->el_entries);
	lockinit(&list->el_lock, PWAIT, name, 0, 0);
	list->el_flags = EHL_INITTED;
    }
    lockmgr(&eventhandler_lock, LK_RELEASE, NULL);

    /* allocate an entry for this handler, populate it */
    eg = malloc(sizeof(struct eventhandler_entry_generic), M_EVENTHANDLER,
		M_WAITOK | M_ZERO);
    eg->func = func;
    eg->ee.ee_arg = arg;
    eg->ee.ee_priority = priority;
    if (priority == EHE_DEAD_PRIORITY) {
	    panic("%s: handler for %s registered with dead priority",
		  __func__, name);
    }

    /* sort it into the list */
    EH_PRINTFN(4, ("%s: adding item %p (function %p) to \"%s\"\n", __func__,
		   eg, func, name));
    EHL_LOCK_ASSERT(list, 0);
    EHL_LOCK(list);
    TAILQ_FOREACH(ep, &list->el_entries, ee_link) {
	if (ep->ee_priority != EHE_DEAD_PRIORITY &&
	    eg->ee.ee_priority < ep->ee_priority) {
	    TAILQ_INSERT_BEFORE(ep, &eg->ee, ee_link);
	    break;
	}
    }
    if (ep == NULL)
	TAILQ_INSERT_TAIL(&list->el_entries, &eg->ee, ee_link);
    EHL_UNLOCK(list);
    return(&eg->ee);
}

/*
 * Remove the given entry from the event handler list or all the entries
 * if tag is NULL.
 */
void
eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag)
{
    struct eventhandler_entry	*ep = tag;

    EHL_LOCK_ASSERT(list, LK_EXCLUSIVE);
    if (ep != NULL) {
	/* remove just this entry */
	if (list->el_runcount == 0) {
	    EH_PRINTFN(3, ("%s: removing item %p from \"%s\"\n", __func__, ep,
		       list->el_name));
	    TAILQ_REMOVE(&list->el_entries, ep, ee_link);
	    free(ep, M_EVENTHANDLER);
	} else {
	    EH_PRINTFN(3, ("%s: marking item %p from \"%s\" as dead\n",
			   __func__, ep, list->el_name));
	    ep->ee_priority = EHE_DEAD_PRIORITY;
	}
    } else {
	/* remove entire list */
	if (list->el_runcount == 0) {
	    EH_PRINTFN(2, ("%s: removing all items from \"%s\"\n", __func__,
		       list->el_name));
	    while (!TAILQ_EMPTY(&list->el_entries)) {
		ep = TAILQ_FIRST(&list->el_entries);
		TAILQ_REMOVE(&list->el_entries, ep, ee_link);
		free(ep, M_EVENTHANDLER);
	    }
	} else {
	    EH_PRINTFN(2, ("%s: marking all items from \"%s\" as dead\n",
		       __func__, list->el_name));
	    TAILQ_FOREACH(ep, &list->el_entries, ee_link)
		ep->ee_priority = EHE_DEAD_PRIORITY;
	}
    }
    EHL_UNLOCK(list);
}

/*
 * Internal version for use when eventhandler list is already locked.
 */
static struct eventhandler_list *
_eventhandler_find_list(const char *name)
{
    struct eventhandler_list	*list;

    KASSERT(lockstatus(&eventhandler_lock) == LK_EXCLUSIVE);
    TAILQ_FOREACH(list, &eventhandler_lists, el_link) {
	if (!strcmp(name, list->el_name))
	    break;
    }
    return (list);
}

/*
 * Lookup a "slow" list by name.  Returns with the list locked.
 */
struct eventhandler_list *
eventhandler_find_list(const char *name)
{
    struct eventhandler_list	*list;

    if (!eventhandler_lists_initted)
	return(NULL);

    /* scan looking for the requested list */
    lockmgr(&eventhandler_lock, LK_EXCLUSIVE, NULL);
    list = _eventhandler_find_list(name);
    if (list != NULL)
	EHL_LOCK(list);
    lockmgr(&eventhandler_lock, LK_RELEASE, NULL);

    return(list);
}

/*
 * Set the attribute flags for the given list. List is expected to be
 * locked on entry, will be unlocked on exit.
 */
void	eventhandler_set_list_flags(struct eventhandler_list *list, int flags)
{
	EHL_LOCK_ASSERT(list, LK_EXCLUSIVE);
	list->el_flags |= flags;
	EHL_UNLOCK(list);
}

/*
 * Set the masking function for the list - when the list is invoked a
 * non-zero return from the mask function will cause the list entry to
 * be executed, otherwise it will be skipped.  List is expected to be
 * locked on entry, will be unlocked on exit.
 */
void	eventhandler_set_mask(struct eventhandler_list *list,
			      int (*fn)(void *))
{
	EHL_LOCK_ASSERT(list, LK_EXCLUSIVE);
	list->el_mask_fn = fn;
	EHL_UNLOCK(list);
}

/*
 * Prune "dead" entries from an eventhandler list.
 */
void
eventhandler_prune_list(struct eventhandler_list *list)
{
    struct eventhandler_entry *ep, *en;

    EH_PRINTFN(2, ("%s: pruning list \"%s\"\n", __func__, list->el_name));
    EHL_LOCK_ASSERT(list, LK_EXCLUSIVE);
    ep = TAILQ_FIRST(&list->el_entries);
    while (ep != NULL) {
	en = TAILQ_NEXT(ep, ee_link);
	if (ep->ee_priority == EHE_DEAD_PRIORITY) {
	    TAILQ_REMOVE(&list->el_entries, ep, ee_link);
	    free(ep, M_EVENTHANDLER);
	}
	ep = en;
    }
}

--/04w6evG8XlLl3ft--