diff options
author | msmith <msmith@FreeBSD.org> | 1999-08-21 06:24:40 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 1999-08-21 06:24:40 +0000 |
commit | b51f157bff8b959d943b0836a1c57f065b9318d5 (patch) | |
tree | e447ab34080a4d202ed41db3476df31ef1f56a50 | |
parent | a753b272ec1066c690e1ba83c8780af55e3a6c78 (diff) | |
download | FreeBSD-src-b51f157bff8b959d943b0836a1c57f065b9318d5.zip FreeBSD-src-b51f157bff8b959d943b0836a1c57f065b9318d5.tar.gz |
Implement a new generic mechanism for attaching handler functions to
events, in order to pave the way for removing a number of the ad-hoc
implementations currently in use.
Retire the at_shutdown family of functions and replace them with
new event handler lists.
Rework kern_shutdown.c to take greater advantage of the use of event
handlers.
Reviewed by: green
-rw-r--r-- | sys/cam/scsi/scsi_da.c | 15 | ||||
-rw-r--r-- | sys/conf/files | 1 | ||||
-rw-r--r-- | sys/dev/aic7xxx/aic7xxx.c | 9 | ||||
-rw-r--r-- | sys/dev/de/if_de.c | 5 | ||||
-rw-r--r-- | sys/dev/dpt/dpt_scsi.c | 11 | ||||
-rw-r--r-- | sys/dev/en/if_en_pci.c | 9 | ||||
-rw-r--r-- | sys/dev/hea/eni.c | 14 | ||||
-rw-r--r-- | sys/dev/hfa/fore_load.c | 13 | ||||
-rw-r--r-- | sys/dev/ie/if_ie.c | 9 | ||||
-rw-r--r-- | sys/dev/pdq/if_fpa.c | 11 | ||||
-rw-r--r-- | sys/dev/syscons/syscons.c | 10 | ||||
-rw-r--r-- | sys/dev/tx/if_tx.c | 11 | ||||
-rw-r--r-- | sys/dev/vx/if_vx_pci.c | 9 | ||||
-rw-r--r-- | sys/dev/wi/if_wi.c | 13 | ||||
-rw-r--r-- | sys/i386/apm/apm.c | 8 | ||||
-rw-r--r-- | sys/i386/bios/apm.c | 8 | ||||
-rw-r--r-- | sys/i386/isa/if_ie.c | 9 | ||||
-rw-r--r-- | sys/i386/isa/if_wi.c | 13 | ||||
-rw-r--r-- | sys/kern/kern_module.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_shutdown.c | 189 | ||||
-rw-r--r-- | sys/kern/subr_eventhandler.c | 140 | ||||
-rw-r--r-- | sys/pci/if_al.c | 13 | ||||
-rw-r--r-- | sys/pci/if_de.c | 5 | ||||
-rw-r--r-- | sys/pci/if_en_pci.c | 9 | ||||
-rw-r--r-- | sys/pci/if_fpa.c | 11 | ||||
-rw-r--r-- | sys/pci/if_rl.c | 13 | ||||
-rw-r--r-- | sys/pci/if_tx.c | 11 | ||||
-rw-r--r-- | sys/pci/if_vx_pci.c | 9 | ||||
-rw-r--r-- | sys/sys/eventhandler.h | 155 | ||||
-rw-r--r-- | sys/sys/systm.h | 16 |
30 files changed, 496 insertions, 263 deletions
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index b23a35d..594ca34 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi_da.c,v 1.32 1999/08/14 11:40:31 phk Exp $ + * $Id: scsi_da.c,v 1.33 1999/08/15 23:34:40 mjacob Exp $ */ #include "opt_hw_wdog.h" @@ -38,6 +38,7 @@ #include <sys/dkbad.h> #include <sys/disklabel.h> #include <sys/diskslice.h> +#include <sys/eventhandler.h> #include <sys/malloc.h> #include <sys/conf.h> #include <sys/cons.h> @@ -198,7 +199,7 @@ static void daprevent(struct cam_periph *periph, int action); static void dasetgeom(struct cam_periph *periph, struct scsi_read_capacity_data * rdcap); static timeout_t dasendorderedtag; -static void dashutdown(int howto, void *arg); +static void dashutdown(void *arg, int howto); #ifndef DA_DEFAULT_TIMEOUT #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */ @@ -815,7 +816,6 @@ dainit(void) printf("da: Failed to attach master async callback " "due to status 0x%x!\n", status); } else { - int err; /* If we were successfull, register our devsw */ cdevsw_add(&da_cdevsw); @@ -827,9 +827,10 @@ dainit(void) timeout(dasendorderedtag, NULL, (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL); - if ((err = at_shutdown(dashutdown, NULL, - SHUTDOWN_POST_SYNC)) != 0) - printf("dainit: at_shutdown returned %d!\n", err); + /* Register our shutdown event handler */ + if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown, + NULL, SHUTDOWN_PRI_DEFAULT)) == NULL) + printf("dainit: shutdown event registration failed!\n"); } } @@ -1553,7 +1554,7 @@ dasendorderedtag(void *arg) * sync the disk cache to physical media. */ static void -dashutdown(int howto, void *arg) +dashutdown(void * arg, int howto) { struct cam_periph *periph; struct da_softc *softc; diff --git a/sys/conf/files b/sys/conf/files index 3f2d236..7bb2733 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -306,6 +306,7 @@ kern/subr_bus.c standard kern/subr_devstat.c standard kern/subr_diskslice.c standard kern/subr_dkbad.c standard +kern/subr_eventhandler.c standard kern/subr_log.c standard kern/subr_module.c standard kern/subr_prf.c standard diff --git a/sys/dev/aic7xxx/aic7xxx.c b/sys/dev/aic7xxx/aic7xxx.c index 7acab86..1d0d043 100644 --- a/sys/dev/aic7xxx/aic7xxx.c +++ b/sys/dev/aic7xxx/aic7xxx.c @@ -36,7 +36,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aic7xxx.c,v 1.31 1999/05/23 18:55:58 gibbs Exp $ + * $Id: aic7xxx.c,v 1.32 1999/08/16 22:49:28 gibbs Exp $ */ /* * A few notes on features of the driver. @@ -96,6 +96,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/eventhandler.h> #include <sys/buf.h> #include <sys/proc.h> @@ -209,7 +210,7 @@ static bus_dmamap_callback_t ahcdmamapcb; #if UNUSED static void ahc_dump_targcmd(struct target_cmd *cmd); #endif -static void ahc_shutdown(int howto, void *arg); +static void ahc_shutdown(void *arg, int howto); static cam_status ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb, @@ -4291,7 +4292,7 @@ ahc_init(struct ahc_softc *ahc) ahc_loadseq(ahc); /* We have to wait until after any system dumps... */ - at_shutdown(ahc_shutdown, ahc, SHUTDOWN_FINAL); + EVENTHANDLER_REGISTER(shutdown_final, ahc_shutdown, ahc, SHUTDOWN_PRI_DEFAULT); return (0); } @@ -6436,7 +6437,7 @@ ahc_dump_targcmd(struct target_cmd *cmd) #endif static void -ahc_shutdown(int howto, void *arg) +ahc_shutdown(void *arg, int howto) { struct ahc_softc *ahc; int i; diff --git a/sys/dev/de/if_de.c b/sys/dev/de/if_de.c index c1a290f..45829b0 100644 --- a/sys/dev/de/if_de.c +++ b/sys/dev/de/if_de.c @@ -5126,7 +5126,7 @@ static struct pci_device dedevice = { COMPAT_PCI_DRIVER(de, dedevice); static void -tulip_shutdown(int howto, void *arg) +tulip_shutdown(void *arg, int howto) { tulip_softc_t * const sc = arg; TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); @@ -5313,7 +5313,8 @@ tulip_pci_attach(pcici_t config_id, int unit) return; } } - at_shutdown(tulip_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, tulip_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); #if defined(TULIP_USE_SOFTINTR) if (sc->tulip_unit > tulip_softintr_max_unit) tulip_softintr_max_unit = sc->tulip_unit; diff --git a/sys/dev/dpt/dpt_scsi.c b/sys/dev/dpt/dpt_scsi.c index bb7362e..aae96a9 100644 --- a/sys/dev/dpt/dpt_scsi.c +++ b/sys/dev/dpt/dpt_scsi.c @@ -43,7 +43,7 @@ * arrays that span controllers (Wow!). */ -#ident "$Id: dpt_scsi.c,v 1.23 1999/05/06 20:16:22 ken Exp $" +#ident "$Id: dpt_scsi.c,v 1.24 1999/08/16 01:49:35 gibbs Exp $" #define _DPT_C_ @@ -155,7 +155,7 @@ static void dptprocesserror(dpt_softc_t *dpt, dpt_ccb_t *dccb, u_int scsi_stat, u_int32_t resid); static void dpttimeout(void *arg); -static void dptshutdown(int howto, void *arg); +static void dptshutdown(void *arg, int howto); /* ================= Private Inline Function definitions ====================*/ static __inline int @@ -1407,7 +1407,8 @@ dpt_attach(dpt_softc_t *dpt) } if (i > 0) - at_shutdown(dptshutdown, dpt, SHUTDOWN_FINAL); + EVENTHANDLER_REGISTER(shutdown_final, dptshutdown, + dpt, SHUTDOWN_PRI_DEFAULT); return (i); } @@ -1639,10 +1640,10 @@ dpttimeout(void *arg) /* * Shutdown the controller and ensure that the cache is completely flushed. - * Called via at_shutdown(9) after all disk access has completed. + * Called from the shutdown_final event after all disk access has completed. */ static void -dptshutdown(int howto, void *arg) +dptshutdown(void *arg, int howto) { dpt_softc_t *dpt; diff --git a/sys/dev/en/if_en_pci.c b/sys/dev/en/if_en_pci.c index 0f0e3a7..30d9e98 100644 --- a/sys/dev/en/if_en_pci.c +++ b/sys/dev/en/if_en_pci.c @@ -70,7 +70,7 @@ static void en_pci_attach __P((pcici_t, int)); static const char *en_pci_probe __P((pcici_t, pcidi_t)); -static void en_pci_shutdown __P((int, void *)); +static void en_pci_shutdown __P((void *, int)); /* * local structures @@ -266,7 +266,8 @@ int unit; * doing so could allow DMA to corrupt kernel memory during the * reboot before the driver initializes. */ - at_shutdown(en_pci_shutdown, scp, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, en_pci_shutdown, scp, + SHUTDOWN_PRI_DEFAULT); if (!pci_map_int(config_id, en_intr, (void *) sc, &net_imask)) { printf("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname); @@ -304,8 +305,8 @@ int unit; static void en_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { struct en_pci_softc *psc = (struct en_pci_softc *)sc; diff --git a/sys/dev/hea/eni.c b/sys/dev/hea/eni.c index f6f1549..7077680 100644 --- a/sys/dev/hea/eni.c +++ b/sys/dev/hea/eni.c @@ -23,7 +23,7 @@ * Copies of this Software may be made, however, the above copyright * notice must be reproduced on all copies. * - * @(#) $Id: eni.c,v 1.7 1999/05/09 17:07:27 peter Exp $ + * @(#) $Id: eni.c,v 1.8 1999/05/10 22:53:41 mks Exp $ * */ @@ -42,7 +42,7 @@ #include <dev/hea/eni_var.h> #ifndef lint -__RCSID("@(#) $Id: eni.c,v 1.7 1999/05/09 17:07:27 peter Exp $"); +__RCSID("@(#) $Id: eni.c,v 1.8 1999/05/10 22:53:41 mks Exp $"); #endif /* @@ -57,7 +57,7 @@ static void eni_read_seeprom __P((Eni_unit *)); #if BSD < 199506 static int eni_pci_shutdown __P((struct kern_devconf *, int)); #else -static void eni_pci_shutdown __P((int, void *)); +static void eni_pci_shutdown __P((void *, int)); #endif static void eni_pci_reset __P((Eni_unit *)); #endif /* __FreeBSD__ */ @@ -549,7 +549,9 @@ eni_pci_attach ( pcici_t config_id, int unit ) /* * Add hook to out shutdown function */ - at_shutdown ( (bootlist_fn)eni_pci_shutdown, eup, SHUTDOWN_POST_SYNC ); + EVENTHANDLER_REGISTER(shutdown_post_sync, eni_pci_shutdown, eup, + SHUTDOWN_PRI_DEFAULT); + #endif /* @@ -654,9 +656,9 @@ eni_pci_shutdown ( kdc, force ) * */ static void -eni_pci_shutdown ( howto, eup ) - int howto; +eni_pci_shutdown ( eup, howto ) void *eup; + int howto; { /* Do device reset */ diff --git a/sys/dev/hfa/fore_load.c b/sys/dev/hfa/fore_load.c index 3921475..f7eeeec 100644 --- a/sys/dev/hfa/fore_load.c +++ b/sys/dev/hfa/fore_load.c @@ -23,7 +23,7 @@ * Copies of this Software may be made, however, the above copyright * notice must be reproduced on all copies. * - * @(#) $Id: fore_load.c,v 1.8 1999/05/10 22:53:45 mks Exp $ + * @(#) $Id: fore_load.c,v 1.9 1999/05/30 16:51:25 phk Exp $ * */ @@ -38,7 +38,7 @@ #include <dev/hfa/fore_include.h> #ifndef lint -__RCSID("@(#) $Id: fore_load.c,v 1.8 1999/05/10 22:53:45 mks Exp $"); +__RCSID("@(#) $Id: fore_load.c,v 1.9 1999/05/30 16:51:25 phk Exp $"); #endif @@ -59,7 +59,7 @@ static void fore_pci_attach __P((pcici_t, int)); #if BSD < 199506 static int fore_pci_shutdown __P((struct kern_devconf *, int)); #else -static void fore_pci_shutdown __P((int, void *)); +static void fore_pci_shutdown __P((void *, int)); #endif #endif static void fore_unattach __P((Fore_unit *)); @@ -1055,7 +1055,8 @@ fore_pci_attach(config_id, unit) /* * Add hook to our shutdown function */ - at_shutdown(fore_pci_shutdown, fup, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, fore_pci_shutdown, fup, + SHUTDOWN_PRI_DEFAULT); #endif /* @@ -1125,9 +1126,9 @@ fore_pci_shutdown(kdc, force) * */ static void -fore_pci_shutdown(howto, fup) - int howto; +fore_pci_shutdown(fup, howto) void *fup; + int howto; { fore_reset((Fore_unit *) fup); diff --git a/sys/dev/ie/if_ie.c b/sys/dev/ie/if_ie.c index f9b155a..b7e04df 100644 --- a/sys/dev/ie/if_ie.c +++ b/sys/dev/ie/if_ie.c @@ -47,7 +47,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_ie.c,v 1.64 1999/08/20 14:12:13 mdodd Exp $ + * $Id: if_ie.c,v 1.65 1999/08/20 14:36:40 mdodd Exp $ */ /* @@ -190,7 +190,7 @@ static void ee16_eeprom_outbits(struct ie_softc * ie, int edata, int cnt); static void ee16_eeprom_clock(struct ie_softc * ie, int state); static u_short ee16_read_eeprom(struct ie_softc * ie, int location); static int ee16_eeprom_inbits(struct ie_softc * ie); -static void ee16_shutdown(int howto, void *sc); +static void ee16_shutdown(void *sc, int howto); static void iereset(int unit); static void ie_readframe(int unit, struct ie_softc * ie, int bufno); @@ -550,7 +550,7 @@ ni_probe(struct isa_device *dvp) static void -ee16_shutdown(int howto, void *sc) +ee16_shutdown(void *sc, int howto) { struct ie_softc *ie = (struct ie_softc *)sc; int unit = ie - &ie_softc[0]; @@ -832,7 +832,8 @@ ieattach(struct isa_device *dvp) ifp->if_hdrlen = 14; if (ie->hard_type == IE_EE16) - at_shutdown(ee16_shutdown, ie, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, ee16_shutdown, + ie, SHUTDOWN_PRI_DEFAULT); #if NBPF > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); diff --git a/sys/dev/pdq/if_fpa.c b/sys/dev/pdq/if_fpa.c index 839b939..57bc72d 100644 --- a/sys/dev/pdq/if_fpa.c +++ b/sys/dev/pdq/if_fpa.c @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_fpa.c,v 1.9 1999/04/24 20:14:00 peter Exp $ + * $Id: if_fpa.c,v 1.10 1999/05/09 17:06:54 peter Exp $ * */ @@ -128,7 +128,7 @@ pdq_pci_ifintr( #endif /* __FreeBSD && BSD */ #if defined(__FreeBSD__) -static void pdq_pci_shutdown(int, void *); +static void pdq_pci_shutdown(void *, int); /* * This is the PCI configuration support. Since the PDQ is available @@ -192,14 +192,15 @@ pdq_pci_attach( pdqs_pci[unit] = sc; pdq_ifattach(sc, pdq_pci_ifwatchdog); pci_map_int(config_id, pdq_pci_ifintr, (void*) sc, &net_imask); - at_shutdown(pdq_pci_shutdown, (void *) sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, pdq_pci_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); } static void pdq_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { pdq_hwreset(((pdq_softc_t *)sc)->sc_pdq); } diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 271f942..8fcaaa4 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: syscons.c,v 1.317 1999/08/13 16:17:54 dt Exp $ + * $Id: syscons.c,v 1.318 1999/08/17 22:06:17 billf Exp $ */ #include "sc.h" @@ -39,6 +39,7 @@ #if NSC > 0 #include <sys/param.h> #include <sys/systm.h> +#include <sys/eventhandler.h> #include <sys/reboot.h> #include <sys/conf.h> #include <sys/proc.h> @@ -140,7 +141,7 @@ static void scinit(int unit, int flags); #if __i386__ static void scterm(int unit, int flags); #endif -static void scshutdown(int howto, void *arg); +static void scshutdown(void *arg, int howto); static u_int scgetc(sc_softc_t *sc, u_int flags); #define SCGETC_CN 1 #define SCGETC_NONBLOCK 2 @@ -359,7 +360,8 @@ sc_attach_unit(int unit, int flags) /* register a shutdown callback for the kernel console */ if (sc_console_unit == unit) - at_shutdown(scshutdown, (void *)(uintptr_t)unit, SHUTDOWN_PRE_SYNC); + EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, + (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT); /* * syscons's cdevsw must be registered from here. As syscons and @@ -3380,7 +3382,7 @@ scterm(int unit, int flags) #endif static void -scshutdown(int howto, void *arg) +scshutdown(void *arg, int howto) { /* assert(sc_console != NULL) */ diff --git a/sys/dev/tx/if_tx.c b/sys/dev/tx/if_tx.c index 8899237..af694f6 100644 --- a/sys/dev/tx/if_tx.c +++ b/sys/dev/tx/if_tx.c @@ -1,5 +1,5 @@ /* $OpenBSD: if_tx.c,v 1.3 1998/10/10 04:30:09 jason Exp $ */ -/* $Id: if_tx.c,v 1.28 1999/07/03 20:17:05 peter Exp $ */ +/* $Id: if_tx.c,v 1.29 1999/07/06 19:23:30 des Exp $ */ /*- * Copyright (c) 1997 Semen Ustimenko (semen@iclub.nsu.ru) @@ -378,7 +378,7 @@ epic_shutdown( static const char* epic_freebsd_probe __P((pcici_t, pcidi_t)); static void epic_freebsd_attach __P((pcici_t, int)); -static void epic_shutdown __P((int, void *)); +static void epic_shutdown __P((void *, int)); /* Global variables */ static u_long epic_pci_count; @@ -546,7 +546,8 @@ epic_freebsd_attach( } /* Set shut down routine to stop DMA processes on reboot */ - at_shutdown(epic_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, epic_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); /* Attach to if manager */ if_attach(ifp); @@ -565,8 +566,8 @@ epic_freebsd_attach( static void epic_shutdown( - int howto, - void *sc) + void *sc, + int howto) { epic_stop(sc); } diff --git a/sys/dev/vx/if_vx_pci.c b/sys/dev/vx/if_vx_pci.c index 2bad3b0..386ba42 100644 --- a/sys/dev/vx/if_vx_pci.c +++ b/sys/dev/vx/if_vx_pci.c @@ -44,14 +44,14 @@ #include <dev/vx/if_vxreg.h> -static void vx_pci_shutdown(int, void *); +static void vx_pci_shutdown(void *, int); static const char *vx_pci_probe(pcici_t, pcidi_t); static void vx_pci_attach(pcici_t, int unit); static void vx_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { vxstop(sc); vxfree(sc); @@ -122,7 +122,8 @@ vx_pci_attach( * doing do could allow DMA to corrupt kernel memory during the * reboot before the driver initializes. */ - at_shutdown(vx_pci_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, vx_pci_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); pci_map_int(config_id, vxintr, (void *) sc, &net_imask); } diff --git a/sys/dev/wi/if_wi.c b/sys/dev/wi/if_wi.c index 4e2b2cf..5b6467f 100644 --- a/sys/dev/wi/if_wi.c +++ b/sys/dev/wi/if_wi.c @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $ + * $Id: if_wi.c,v 1.8 1999/07/06 19:22:53 des Exp $ */ /* @@ -116,7 +116,7 @@ #if !defined(lint) static const char rcsid[] = - "$Id: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $"; + "$Id: if_wi.c,v 1.8 1999/07/06 19:22:53 des Exp $"; #endif static struct wi_softc wi_softc[NWI]; @@ -136,7 +136,7 @@ static void wi_init __P((void *)); static void wi_start __P((struct ifnet *)); static void wi_stop __P((struct wi_softc *)); static void wi_watchdog __P((struct ifnet *)); -static void wi_shutdown __P((int, void *)); +static void wi_shutdown __P((void *, int)); static void wi_rxeof __P((struct wi_softc *)); static void wi_txeof __P((struct wi_softc *, int)); static void wi_update_stats __P((struct wi_softc *)); @@ -367,7 +367,8 @@ static int wi_attach(isa_dev) bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif - at_shutdown(wi_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, wi_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); } return(0); @@ -1336,9 +1337,9 @@ static void wi_watchdog(ifp) return; } -static void wi_shutdown(howto, arg) - int howto; +static void wi_shutdown(arg, howto) void *arg; + int howto; { struct wi_softc *sc; diff --git a/sys/i386/apm/apm.c b/sys/i386/apm/apm.c index d2c2264..1beb8b5 100644 --- a/sys/i386/apm/apm.c +++ b/sys/i386/apm/apm.c @@ -15,13 +15,14 @@ * * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * - * $Id: apm.c,v 1.98 1999/08/02 18:46:34 msmith Exp $ + * $Id: apm.c,v 1.99 1999/08/14 18:39:40 iwasaki Exp $ */ #include "opt_devfs.h" #include <sys/param.h> #include <sys/systm.h> +#include <sys/eventhandler.h> #include <sys/conf.h> #include <sys/kernel.h> #ifdef DEVFS @@ -302,7 +303,7 @@ apm_display(int newstate) * Turn off the entire system. */ static void -apm_power_off(int howto, void *junk) +apm_power_off(void *junk, int howto) { struct apm_softc *sc = &apm_softc; @@ -1047,7 +1048,8 @@ apm_attach(device_t dev) apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume); /* Power the system off using APM */ - at_shutdown_pri(apm_power_off, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_LAST); + EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL, + SHUTDOWN_PRI_LAST); sc->initialized = 1; diff --git a/sys/i386/bios/apm.c b/sys/i386/bios/apm.c index d2c2264..1beb8b5 100644 --- a/sys/i386/bios/apm.c +++ b/sys/i386/bios/apm.c @@ -15,13 +15,14 @@ * * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * - * $Id: apm.c,v 1.98 1999/08/02 18:46:34 msmith Exp $ + * $Id: apm.c,v 1.99 1999/08/14 18:39:40 iwasaki Exp $ */ #include "opt_devfs.h" #include <sys/param.h> #include <sys/systm.h> +#include <sys/eventhandler.h> #include <sys/conf.h> #include <sys/kernel.h> #ifdef DEVFS @@ -302,7 +303,7 @@ apm_display(int newstate) * Turn off the entire system. */ static void -apm_power_off(int howto, void *junk) +apm_power_off(void *junk, int howto) { struct apm_softc *sc = &apm_softc; @@ -1047,7 +1048,8 @@ apm_attach(device_t dev) apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume); /* Power the system off using APM */ - at_shutdown_pri(apm_power_off, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_LAST); + EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL, + SHUTDOWN_PRI_LAST); sc->initialized = 1; diff --git a/sys/i386/isa/if_ie.c b/sys/i386/isa/if_ie.c index f9b155a..b7e04df 100644 --- a/sys/i386/isa/if_ie.c +++ b/sys/i386/isa/if_ie.c @@ -47,7 +47,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_ie.c,v 1.64 1999/08/20 14:12:13 mdodd Exp $ + * $Id: if_ie.c,v 1.65 1999/08/20 14:36:40 mdodd Exp $ */ /* @@ -190,7 +190,7 @@ static void ee16_eeprom_outbits(struct ie_softc * ie, int edata, int cnt); static void ee16_eeprom_clock(struct ie_softc * ie, int state); static u_short ee16_read_eeprom(struct ie_softc * ie, int location); static int ee16_eeprom_inbits(struct ie_softc * ie); -static void ee16_shutdown(int howto, void *sc); +static void ee16_shutdown(void *sc, int howto); static void iereset(int unit); static void ie_readframe(int unit, struct ie_softc * ie, int bufno); @@ -550,7 +550,7 @@ ni_probe(struct isa_device *dvp) static void -ee16_shutdown(int howto, void *sc) +ee16_shutdown(void *sc, int howto) { struct ie_softc *ie = (struct ie_softc *)sc; int unit = ie - &ie_softc[0]; @@ -832,7 +832,8 @@ ieattach(struct isa_device *dvp) ifp->if_hdrlen = 14; if (ie->hard_type == IE_EE16) - at_shutdown(ee16_shutdown, ie, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, ee16_shutdown, + ie, SHUTDOWN_PRI_DEFAULT); #if NBPF > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); diff --git a/sys/i386/isa/if_wi.c b/sys/i386/isa/if_wi.c index 4e2b2cf..5b6467f 100644 --- a/sys/i386/isa/if_wi.c +++ b/sys/i386/isa/if_wi.c @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $ + * $Id: if_wi.c,v 1.8 1999/07/06 19:22:53 des Exp $ */ /* @@ -116,7 +116,7 @@ #if !defined(lint) static const char rcsid[] = - "$Id: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $"; + "$Id: if_wi.c,v 1.8 1999/07/06 19:22:53 des Exp $"; #endif static struct wi_softc wi_softc[NWI]; @@ -136,7 +136,7 @@ static void wi_init __P((void *)); static void wi_start __P((struct ifnet *)); static void wi_stop __P((struct wi_softc *)); static void wi_watchdog __P((struct ifnet *)); -static void wi_shutdown __P((int, void *)); +static void wi_shutdown __P((void *, int)); static void wi_rxeof __P((struct wi_softc *)); static void wi_txeof __P((struct wi_softc *, int)); static void wi_update_stats __P((struct wi_softc *)); @@ -367,7 +367,8 @@ static int wi_attach(isa_dev) bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif - at_shutdown(wi_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, wi_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); } return(0); @@ -1336,9 +1337,9 @@ static void wi_watchdog(ifp) return; } -static void wi_shutdown(howto, arg) - int howto; +static void wi_shutdown(arg, howto) void *arg; + int howto; { struct wi_softc *sc; diff --git a/sys/kern/kern_module.c b/sys/kern/kern_module.c index f380386..19dd2be 100644 --- a/sys/kern/kern_module.c +++ b/sys/kern/kern_module.c @@ -23,12 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_module.c,v 1.17 1999/05/08 13:01:57 peter Exp $ + * $Id: kern_module.c,v 1.18 1999/05/20 00:00:58 peter Exp $ */ #include <sys/param.h> #include <sys/kernel.h> #include <sys/systm.h> +#include <sys/eventhandler.h> #include <sys/malloc.h> #include <sys/sysproto.h> #include <sys/sysent.h> @@ -56,19 +57,20 @@ struct module { static modulelist_t modules; static int nextid = 1; -static void module_shutdown(int, void*); +static void module_shutdown(void*, int); static void module_init(void* arg) { TAILQ_INIT(&modules); - at_shutdown(module_shutdown, 0, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, module_shutdown, NULL, + SHUTDOWN_PRI_DEFAULT); } SYSINIT(module, SI_SUB_KLD, SI_ORDER_FIRST, module_init, 0); static void -module_shutdown(int arg1, void* arg2) +module_shutdown(void* arg1, int arg2) { module_t mod; diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 8465777..4df03a7 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 - * $Id: kern_shutdown.c,v 1.59 1999/08/11 14:02:20 alfred Exp $ + * $Id: kern_shutdown.c,v 1.60 1999/08/13 10:29:21 phk Exp $ */ #include "opt_ddb.h" @@ -46,6 +46,7 @@ #include <sys/param.h> #include <sys/systm.h> +#include <sys/eventhandler.h> #include <sys/buf.h> #include <sys/reboot.h> #include <sys/proc.h> @@ -107,34 +108,26 @@ watchdog_tickle_fn wdog_tickler = NULL; */ const char *panicstr; -/* - * callout list for things to do a shutdown - */ -typedef struct shutdown_list_element { - LIST_ENTRY(shutdown_list_element) links; - bootlist_fn function; - void *arg; - int priority; -} *sle_p; - -/* - * There are three shutdown lists. Some things need to be shut down - * earlier than others. - */ -LIST_HEAD(shutdown_list, shutdown_list_element); - -static struct shutdown_list shutdown_lists[SHUTDOWN_FINAL + 1]; - static void boot __P((int)) __dead2; static void dumpsys __P((void)); static int setdumpdev __P((dev_t dev)); +static void poweroff_wait __P((void *, int)); +static void shutdown_halt __P((void *junk, int howto)); +static void shutdown_panic __P((void *junk, int howto)); +static void shutdown_reset __P((void *junk, int howto)); + +/* register various local shutdown events */ +static void +shutdown_conf(void *unused) +{ + EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL, SHUTDOWN_PRI_FIRST); + EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL, SHUTDOWN_PRI_LAST + 100); + EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL, SHUTDOWN_PRI_LAST + 100); + EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL, SHUTDOWN_PRI_LAST + 200); +} +SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL) -#ifndef _SYS_SYSPROTO_H_ -struct reboot_args { - int opt; -}; -#endif /* ARGSUSED */ /* @@ -181,7 +174,6 @@ static void boot(howto) int howto; { - sle_p ep; #ifdef SMP if (smp_active) { @@ -191,8 +183,7 @@ boot(howto) /* * Do any callouts that should be done BEFORE syncing the filesystems. */ - LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_PRE_SYNC], links) - (*ep->function)(howto, ep->arg); + EVENTHANDLER_INVOKE(shutdown_pre_sync, howto); /* * Now sync filesystems @@ -282,8 +273,7 @@ boot(howto) * Ok, now do things that assume all filesystem activity has * been completed. */ - LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_POST_SYNC], links) - (*ep->function)(howto, ep->arg); + EVENTHANDLER_INVOKE(shutdown_post_sync, howto); splhigh(); if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold) { savectx(&dumppcb); @@ -294,9 +284,18 @@ boot(howto) } /* Now that we're going to really halt the system... */ - LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_FINAL], links) - (*ep->function)(howto, ep->arg); + EVENTHANDLER_INVOKE(shutdown_final, howto); + + for(;;) ; /* safety against shutdown_reset not working */ + /* NOTREACHED */ +} +/* + * If the shutdown was a clean halt, behave accordingly. + */ +static void +shutdown_halt(void *junk, int howto) +{ if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); @@ -309,12 +308,21 @@ boot(howto) howto &= ~RB_HALT; break; } - } else if (howto & RB_DUMP) { - /* System Paniced */ + } +} + +/* + * Check to see if the system paniced, pause and then reboot + * according to the specified delay. + */ +static void +shutdown_panic(void *junk, int howto) +{ + int loop; + if (howto & RB_DUMP) { if (PANIC_REBOOT_WAIT_TIME != 0) { if (PANIC_REBOOT_WAIT_TIME != -1) { - int loop; printf("Automatic reboot in %d seconds - " "press a key on the console to abort\n", PANIC_REBOOT_WAIT_TIME); @@ -326,21 +334,27 @@ boot(howto) break; } if (!loop) - goto die; + return; } } else { /* zero time specified - reboot NOW */ - goto die; + return; } printf("--> Press a key on the console to reboot <--\n"); cngetc(); } -die: +} + +/* + * Everything done, now reset + */ +static void +shutdown_reset(void *junk, int howto) +{ printf("Rebooting...\n"); DELAY(1000000); /* wait 1 sec for printf's to complete and be read */ /* cpu_boot(howto); */ /* doesn't do anything at the moment */ cpu_reset(); - for(;;) ; - /* NOTREACHED */ + /* NOTREACHED */ /* assuming reset worked */ } /* @@ -516,109 +530,16 @@ panic(const char *fmt, ...) } /* - * Three routines to handle adding/deleting items on the - * shutdown callout lists - * - * at_shutdown(): - * Take the arguments given and put them onto the shutdown callout list. - * However first make sure that it's not already there. - * returns 0 on success. - */ -int -at_shutdown(bootlist_fn function, void *arg, int queue) -{ - return(at_shutdown_pri(function, arg, queue, SHUTDOWN_PRI_DEFAULT)); -} - -/* - * at_shutdown_pri(): - * Take the arguments given and put them onto the shutdown callout list - * with the given execution priority. - * returns 0 on success. - */ -int -at_shutdown_pri(bootlist_fn function, void *arg, int queue, int pri) -{ - sle_p op, ep, ip; - - op = NULL; /* shut up gcc */ - if (queue < SHUTDOWN_PRE_SYNC - || queue > SHUTDOWN_FINAL) { - printf("at_shutdown: bad exit callout queue %d specified\n", - queue); - return (EINVAL); - } - if (rm_at_shutdown(function, arg)) - printf("at_shutdown: exit callout entry was already present\n"); - ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); - if (ep == NULL) - return (ENOMEM); - ep->function = function; - ep->arg = arg; - ep->priority = pri; - - /* Sort into list of items on this queue */ - ip = LIST_FIRST(&shutdown_lists[queue]); - if (ip == NULL) { - LIST_INSERT_HEAD(&shutdown_lists[queue], ep, links); - } else { - for (; ip != NULL; op = ip, ip = LIST_NEXT(ip, links)) { - if (ep->priority < ip->priority) { - LIST_INSERT_BEFORE(ip, ep, links); - ep = NULL; - break; - } - } - if (ep != NULL) - LIST_INSERT_AFTER(op, ep, links); - } - return (0); -} - -/* - * Scan the exit callout lists for the given items and remove them. - * Returns the number of items removed. - */ -int -rm_at_shutdown(bootlist_fn function, void *arg) -{ - sle_p ep; - int count; - int queue; - - count = 0; - for (queue = SHUTDOWN_PRE_SYNC; queue < SHUTDOWN_FINAL; queue++) { - LIST_FOREACH(ep, &shutdown_lists[queue], links) { - if ((ep->function == function) && (ep->arg == arg)) { - LIST_REMOVE(ep, links); - free(ep, M_TEMP); - count++; - } - } - } - return (count); -} - -/* * Support for poweroff delay. */ static int poweroff_delay = 0; SYSCTL_INT(_kern_shutdown, OID_AUTO, poweroff_delay, CTLFLAG_RW, &poweroff_delay, 0, ""); -static void poweroff_wait(int howto, void *unused) +static void +poweroff_wait(void *junk, int howto) { if(!(howto & RB_POWEROFF) || poweroff_delay <= 0) return; DELAY(poweroff_delay * 1000); } - -/* - * XXX OK? This implies I know SHUTDOWN_PRI_LAST > SHUTDOWN_PRI_FIRST - */ -static void poweroff_conf(void *unused) -{ - at_shutdown_pri(poweroff_wait, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_FIRST); -} - -SYSINIT(poweroff_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, poweroff_conf, NULL) diff --git a/sys/kern/subr_eventhandler.c b/sys/kern/subr_eventhandler.c new file mode 100644 index 0000000..2caef17 --- /dev/null +++ b/sys/kern/subr_eventhandler.c @@ -0,0 +1,140 @@ +/*- + * 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. + * + * $Id$ + */ + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/systm.h> +#include <sys/eventhandler.h> + +MALLOC_DEFINE(M_EVENTHANDLER, "eventhandler", "Event handler records"); + +/* List of 'slow' lists */ +static TAILQ_HEAD(, eventhandler_list) eventhandler_lists; +static int eventhandler_lists_initted = 0; + +struct eventhandler_entry_generic +{ + struct eventhandler_entry ee; + void (* func)(void); +}; + +/* + * 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, char *name, + void *func, void *arg, int priority) +{ + struct eventhandler_entry_generic *eg; + struct eventhandler_entry *ep; + + /* avoid the need for a SYSINIT just to init the list */ + if (!eventhandler_lists_initted) { + TAILQ_INIT(&eventhandler_lists); + eventhandler_lists_initted = 1; + } + + /* 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) { + if ((list = malloc(sizeof(struct eventhandler_list) + strlen(name) + 1, + M_EVENTHANDLER, M_NOWAIT)) == NULL) + return(NULL); + list->el_flags = 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 & EHE_INITTED)) { + TAILQ_INIT(&list->el_entries); + list->el_flags = EHE_INITTED; + } + + /* allocate an entry for this handler, populate it */ + if ((eg = malloc(sizeof(struct eventhandler_entry_generic), + M_EVENTHANDLER, M_NOWAIT)) == NULL) + return(NULL); + eg->func = func; + eg->ee.ee_arg = arg; + eg->ee.ee_priority = priority; + + /* sort it into the list */ + for (ep = TAILQ_FIRST(&list->el_entries); + ep != NULL; + ep = TAILQ_NEXT(ep, ee_link)) { + if (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); + return(&eg->ee); +} + +void +eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag) +{ + struct eventhandler_entry *ep = tag; + + /* XXX insert diagnostic check here? */ + if (ep != NULL) { + /* remove just this entry */ + TAILQ_REMOVE(&list->el_entries, ep, ee_link); + free(ep, M_EVENTHANDLER); + } else { + /* remove entire list */ + while (!TAILQ_EMPTY(&list->el_entries)) { + ep = TAILQ_FIRST(&list->el_entries); + TAILQ_REMOVE(&list->el_entries, list->el_entries.tqh_first, ee_link); + free(ep, M_EVENTHANDLER); + } + } +} + +struct eventhandler_list * +eventhandler_find_list(char *name) +{ + struct eventhandler_list *list; + + /* scan looking for the requested list */ + for (list = TAILQ_FIRST(&eventhandler_lists); + list != NULL; + list = TAILQ_NEXT(list, el_link)) { + if (!strcmp(name, list->el_name)) + break; + } + return(list); +} diff --git a/sys/pci/if_al.c b/sys/pci/if_al.c index ab299eb..ba36544 100644 --- a/sys/pci/if_al.c +++ b/sys/pci/if_al.c @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_al.c,v 1.5 1999/07/02 04:17:12 peter Exp $ + * $Id: if_al.c,v 1.6 1999/07/06 19:23:22 des Exp $ */ /* @@ -90,7 +90,7 @@ #ifndef lint static const char rcsid[] = - "$Id: if_al.c,v 1.5 1999/07/02 04:17:12 peter Exp $"; + "$Id: if_al.c,v 1.6 1999/07/06 19:23:22 des Exp $"; #endif /* @@ -137,7 +137,7 @@ static int al_ioctl __P((struct ifnet *, u_long, caddr_t)); static void al_init __P((void *)); static void al_stop __P((struct al_softc *)); static void al_watchdog __P((struct ifnet *)); -static void al_shutdown __P((int, void *)); +static void al_shutdown __P((void *, int)); static int al_ifmedia_upd __P((struct ifnet *)); static void al_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); @@ -1069,7 +1069,8 @@ al_attach(config_id, unit) #if NBPF > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif - at_shutdown(al_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, al_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); fail: splx(s); @@ -1976,9 +1977,9 @@ static void al_stop(sc) * Stop all chip I/O so that the kernel's probe routines don't * get confused by errant DMAs when rebooting. */ -static void al_shutdown(howto, arg) - int howto; +static void al_shutdown(arg, howto) void *arg; + int howto; { struct al_softc *sc = (struct al_softc *)arg; diff --git a/sys/pci/if_de.c b/sys/pci/if_de.c index c1a290f..45829b0 100644 --- a/sys/pci/if_de.c +++ b/sys/pci/if_de.c @@ -5126,7 +5126,7 @@ static struct pci_device dedevice = { COMPAT_PCI_DRIVER(de, dedevice); static void -tulip_shutdown(int howto, void *arg) +tulip_shutdown(void *arg, int howto) { tulip_softc_t * const sc = arg; TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); @@ -5313,7 +5313,8 @@ tulip_pci_attach(pcici_t config_id, int unit) return; } } - at_shutdown(tulip_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, tulip_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); #if defined(TULIP_USE_SOFTINTR) if (sc->tulip_unit > tulip_softintr_max_unit) tulip_softintr_max_unit = sc->tulip_unit; diff --git a/sys/pci/if_en_pci.c b/sys/pci/if_en_pci.c index 0f0e3a7..30d9e98 100644 --- a/sys/pci/if_en_pci.c +++ b/sys/pci/if_en_pci.c @@ -70,7 +70,7 @@ static void en_pci_attach __P((pcici_t, int)); static const char *en_pci_probe __P((pcici_t, pcidi_t)); -static void en_pci_shutdown __P((int, void *)); +static void en_pci_shutdown __P((void *, int)); /* * local structures @@ -266,7 +266,8 @@ int unit; * doing so could allow DMA to corrupt kernel memory during the * reboot before the driver initializes. */ - at_shutdown(en_pci_shutdown, scp, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, en_pci_shutdown, scp, + SHUTDOWN_PRI_DEFAULT); if (!pci_map_int(config_id, en_intr, (void *) sc, &net_imask)) { printf("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname); @@ -304,8 +305,8 @@ int unit; static void en_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { struct en_pci_softc *psc = (struct en_pci_softc *)sc; diff --git a/sys/pci/if_fpa.c b/sys/pci/if_fpa.c index 839b939..57bc72d 100644 --- a/sys/pci/if_fpa.c +++ b/sys/pci/if_fpa.c @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_fpa.c,v 1.9 1999/04/24 20:14:00 peter Exp $ + * $Id: if_fpa.c,v 1.10 1999/05/09 17:06:54 peter Exp $ * */ @@ -128,7 +128,7 @@ pdq_pci_ifintr( #endif /* __FreeBSD && BSD */ #if defined(__FreeBSD__) -static void pdq_pci_shutdown(int, void *); +static void pdq_pci_shutdown(void *, int); /* * This is the PCI configuration support. Since the PDQ is available @@ -192,14 +192,15 @@ pdq_pci_attach( pdqs_pci[unit] = sc; pdq_ifattach(sc, pdq_pci_ifwatchdog); pci_map_int(config_id, pdq_pci_ifintr, (void*) sc, &net_imask); - at_shutdown(pdq_pci_shutdown, (void *) sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, pdq_pci_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); } static void pdq_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { pdq_hwreset(((pdq_softc_t *)sc)->sc_pdq); } diff --git a/sys/pci/if_rl.c b/sys/pci/if_rl.c index c7935ff..8fc7fbe 100644 --- a/sys/pci/if_rl.c +++ b/sys/pci/if_rl.c @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_rl.c,v 1.19 1999/07/06 19:23:28 des Exp $ + * $Id: if_rl.c,v 1.20 1999/07/22 20:56:49 wpaul Exp $ */ /* @@ -127,7 +127,7 @@ #ifndef lint static const char rcsid[] = - "$Id: if_rl.c,v 1.19 1999/07/06 19:23:28 des Exp $"; + "$Id: if_rl.c,v 1.20 1999/07/22 20:56:49 wpaul Exp $"; #endif /* @@ -177,7 +177,7 @@ static int rl_ioctl __P((struct ifnet *, u_long, caddr_t)); static void rl_init __P((void *)); static void rl_stop __P((struct rl_softc *)); static void rl_watchdog __P((struct ifnet *)); -static void rl_shutdown __P((int, void *)); +static void rl_shutdown __P((void *, int)); static int rl_ifmedia_upd __P((struct ifnet *)); static void rl_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); @@ -1234,7 +1234,8 @@ rl_attach(config_id, unit) #if NBPF > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif - at_shutdown(rl_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, rl_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); fail: splx(s); @@ -1925,9 +1926,9 @@ static void rl_stop(sc) * Stop all chip I/O so that the kernel's probe routines don't * get confused by errant DMAs when rebooting. */ -static void rl_shutdown(howto, arg) - int howto; +static void rl_shutdown(arg, howto) void *arg; + int howto; { struct rl_softc *sc = (struct rl_softc *)arg; diff --git a/sys/pci/if_tx.c b/sys/pci/if_tx.c index 8899237..af694f6 100644 --- a/sys/pci/if_tx.c +++ b/sys/pci/if_tx.c @@ -1,5 +1,5 @@ /* $OpenBSD: if_tx.c,v 1.3 1998/10/10 04:30:09 jason Exp $ */ -/* $Id: if_tx.c,v 1.28 1999/07/03 20:17:05 peter Exp $ */ +/* $Id: if_tx.c,v 1.29 1999/07/06 19:23:30 des Exp $ */ /*- * Copyright (c) 1997 Semen Ustimenko (semen@iclub.nsu.ru) @@ -378,7 +378,7 @@ epic_shutdown( static const char* epic_freebsd_probe __P((pcici_t, pcidi_t)); static void epic_freebsd_attach __P((pcici_t, int)); -static void epic_shutdown __P((int, void *)); +static void epic_shutdown __P((void *, int)); /* Global variables */ static u_long epic_pci_count; @@ -546,7 +546,8 @@ epic_freebsd_attach( } /* Set shut down routine to stop DMA processes on reboot */ - at_shutdown(epic_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, epic_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); /* Attach to if manager */ if_attach(ifp); @@ -565,8 +566,8 @@ epic_freebsd_attach( static void epic_shutdown( - int howto, - void *sc) + void *sc, + int howto) { epic_stop(sc); } diff --git a/sys/pci/if_vx_pci.c b/sys/pci/if_vx_pci.c index 2bad3b0..386ba42 100644 --- a/sys/pci/if_vx_pci.c +++ b/sys/pci/if_vx_pci.c @@ -44,14 +44,14 @@ #include <dev/vx/if_vxreg.h> -static void vx_pci_shutdown(int, void *); +static void vx_pci_shutdown(void *, int); static const char *vx_pci_probe(pcici_t, pcidi_t); static void vx_pci_attach(pcici_t, int unit); static void vx_pci_shutdown( - int howto, - void *sc) + void *sc, + int howto) { vxstop(sc); vxfree(sc); @@ -122,7 +122,8 @@ vx_pci_attach( * doing do could allow DMA to corrupt kernel memory during the * reboot before the driver initializes. */ - at_shutdown(vx_pci_shutdown, sc, SHUTDOWN_POST_SYNC); + EVENTHANDLER_REGISTER(shutdown_post_sync, vx_pci_shutdown, sc, + SHUTDOWN_PRI_DEFAULT); pci_map_int(config_id, vxintr, (void *) sc, &net_imask); } diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h new file mode 100644 index 0000000..9620f5d --- /dev/null +++ b/sys/sys/eventhandler.h @@ -0,0 +1,155 @@ +/*- + * 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. + * + * $Id$ + */ + +#include <sys/queue.h> + +#ifndef SYS_EVENTHANDLER_H +#define SYS_EVENTHANDLER_H + +struct eventhandler_entry +{ + TAILQ_ENTRY(eventhandler_entry) ee_link; + int ee_priority; + void *ee_arg; +}; + +struct eventhandler_list +{ + TAILQ_ENTRY(eventhandler_list) el_link; + char *el_name; + int el_flags; +#define EHE_INITTED (1<<0) + TAILQ_HEAD(,eventhandler_entry) el_entries; +}; + +typedef struct eventhandler_entry *eventhandler_tag; + +/* + * Fast handler lists require the eventhandler list be present + * at link time. They don't allow addition of entries to + * unknown eventhandler lists, ie. each list must have an + * "owner". + * + * Fast handler lists must be defined once by the owner + * of the eventhandler list, and the declaration must be in + * scope at any point the list is manipulated. + */ +#define EVENTHANDLER_FAST_DECLARE(name, type) \ +extern struct eventhandler_list Xeventhandler_list_ ## name ; \ +struct eventhandler_entry_ ## name \ +{ \ + struct eventhandler_entry ee; \ + type eh_func; \ +}; + +#define EVENTHANDLER_FAST_DEFINE(name, type) \ +struct eventhandler_list Xeventhandler_list_ ## name = { #name }; + +#define EVENTHANDLER_FAST_INVOKE(name, args...) \ +do { \ + struct eventhandler_list *_el = &Xeventhandler_list ## name ; \ + struct eventhandler_entry *_ep = TAILQ_FIRST(&(_el->el_entries)); \ + \ + while (_ep != NULL) { \ + ((struct eventhandler_entry_ ## name *)_ep)->eh_func(_ep->ee_arg , ## args); \ + _ep = TAILQ_NEXT(_ep, ee_link); \ + } \ +} while (0); + +#define EVENTHANDLER_FAST_REGISTER(name, func, arg, priority) \ + eventhandler_register(Xeventhandler_list_ ## name, #name, func, arg, priority) + +#define EVENTHANDLER_FAST_DEREGISTER(name, tag, func) \ + eventhandler_deregister(Xeventhandler_list ## name, tag, func) + + +/* + * Slow handlerss are entirely dynamic; lists are created + * when entries are added to them, and thus have no concept of "owner", + * + * Slow handlerss 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, args...) \ +do { \ + struct eventhandler_list *_el; \ + struct eventhandler_entry *_ep; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) { \ + for (_ep = TAILQ_FIRST(&(_el->el_entries)); \ + _ep != NULL; \ + _ep = TAILQ_NEXT(_ep, ee_link)) { \ + ((struct eventhandler_entry_ ## name *)_ep)->eh_func(_ep->ee_arg , ## args); \ + } \ + } \ +} while (0); + +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ + eventhandler_register(NULL, #name, func, arg, priority) + +#define EVENTHANDLER_DEREGISTER(name, tag, func) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + eventhandler_deregister(_el, tag, func); \ +} while(0); + + +extern eventhandler_tag eventhandler_register(struct eventhandler_list *list, + char *name, + void *func, + void *arg, + int priority); +extern void eventhandler_deregister(struct eventhandler_list *list, + eventhandler_tag tag); +extern struct eventhandler_list *eventhandler_find_list(char *name); + +/* + * Standard system event queues. + */ + +/* Shutdown events */ +typedef void (*shutdown_fn) __P((void *, int)); + +#define SHUTDOWN_PRI_FIRST 0 +#define SHUTDOWN_PRI_DEFAULT 10000 +#define SHUTDOWN_PRI_LAST 20000 + +EVENTHANDLER_DECLARE(shutdown_pre_sync, shutdown_fn); /* before fs sync */ +EVENTHANDLER_DECLARE(shutdown_post_sync, shutdown_fn); /* after fs sync */ +EVENTHANDLER_DECLARE(shutdown_final, shutdown_fn); + +#endif /* SYS_EVENTHANDLER_H */ diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 4ddf974..e2fdc9f 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)systm.h 8.7 (Berkeley) 3/29/95 - * $Id: systm.h,v 1.94 1999/07/23 23:45:50 alc Exp $ + * $Id: systm.h,v 1.95 1999/07/24 09:34:11 dfr Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -269,20 +269,6 @@ typedef void (*forklist_fn) __P((struct proc *parent, struct proc *child, int at_fork __P((forklist_fn function)); int rm_at_fork __P((forklist_fn function)); -/* Shutdown callout list definitions and declarations. */ -#define SHUTDOWN_PRE_SYNC 0 -#define SHUTDOWN_POST_SYNC 1 -#define SHUTDOWN_FINAL 2 -#define SHUTDOWN_PRI_FIRST 0 -#define SHUTDOWN_PRI_DEFAULT 10000 -#define SHUTDOWN_PRI_LAST 20000 - -typedef void (*bootlist_fn) __P((int, void *)); - -int at_shutdown __P((bootlist_fn function, void *arg, int position)); -int at_shutdown_pri __P((bootlist_fn function, void *arg, int position, int pri)); -int rm_at_shutdown __P((bootlist_fn function, void *arg)); - /* * Not exactly a callout LIST, but a callout entry. * Allow an external module to define a hardware watchdog tickler. |