diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/i386/apm.c | 45 | ||||
-rw-r--r-- | sys/kern/kern_subr.c | 68 | ||||
-rw-r--r-- | sys/sys/systm.h | 12 |
3 files changed, 112 insertions, 13 deletions
diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c index d1825fa5c8f..d3d18c79de7 100644 --- a/sys/arch/i386/i386/apm.c +++ b/sys/arch/i386/i386/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.26 1999/02/28 05:53:13 deraadt Exp $ */ +/* $OpenBSD: apm.c,v 1.27 1999/11/07 17:39:15 provos Exp $ */ /*- * Copyright (c) 1995 John T. Kohl. All rights reserved. @@ -155,8 +155,9 @@ STATIC const char *apm_err_translate __P((int code)); #define apm_get_powstat(r) apmcall(APM_POWER_STATUS, APM_DEV_ALLDEVS, &r) #define apm_get_event(r) apmcall(APM_GET_PM_EVENT, 0, &r) -#define apm_suspend() apm_set_powstate(APM_DEV_ALLDEVS, APM_SYS_SUSPEND) -#define apm_standby() apm_set_powstate(APM_DEV_ALLDEVS, APM_SYS_STANDBY) +STATIC void apm_standby __P((void)); +STATIC void apm_suspend __P((void)); +STATIC void apm_resume __P((struct apm_softc *, struct apmregs *)); STATIC const char * apm_err_translate(code) @@ -284,6 +285,32 @@ apm_power_print (sc, regs) #endif } +STATIC void +apm_suspend() +{ + dopowerhooks(PWR_SUSPEND); + + (void)apm_set_powstate(APM_DEV_ALLDEVS, APM_SYS_SUSPEND); +} + +STATIC void +apm_standby() +{ + dopowerhooks(PWR_STANDBY); + + (void)apm_set_powstate(APM_DEV_ALLDEVS, APM_SYS_STANDBY); +} + +STATIC void +apm_resume(sc, regs) + struct apm_softc *sc; + struct apmregs *regs; +{ + inittodr(time.tv_sec); + dopowerhooks(PWR_RESUME); + apm_record_event(sc, regs->bx); +} + /* * call the APM protected mode bios function FUNCTION for BIOS selection * WHICHBIOS. @@ -411,23 +438,19 @@ apm_event_handle(sc, regs) break; case APM_NORMAL_RESUME: DPRINTF(("system resumed\n")); - inittodr(time.tv_sec); - apm_record_event(sc, regs->bx); + apm_resume(sc, regs); break; case APM_CRIT_RESUME: DPRINTF(("system resumed without us!\n")); - inittodr(time.tv_sec); - apm_record_event(sc, regs->bx); + apm_resume(sc, regs); break; case APM_SYS_STANDBY_RESUME: DPRINTF(("system standby resume\n")); - inittodr(time.tv_sec); - apm_record_event(sc, regs->bx); + apm_resume(sc, regs); break; case APM_UPDATE_TIME: DPRINTF(("update time, please\n")); - inittodr(time.tv_sec); - apm_record_event(sc, regs->bx); + apm_resume(sc, regs); break; case APM_CRIT_SUSPEND_REQ: DPRINTF(("suspend required immediately\n")); diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index be226f857e8..4a6321e1896 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_subr.c,v 1.9 1999/04/28 09:28:15 art Exp $ */ +/* $OpenBSD: kern_subr.c,v 1.10 1999/11/07 17:39:14 provos Exp $ */ /* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */ /* @@ -249,3 +249,69 @@ doshutdownhooks() dp->sfd_list.le_next) (*dp->sfd_fn)(dp->sfd_arg); } + +/* + * "Power hook" types, functions, and variables. + */ + +struct powerhook_desc { + LIST_ENTRY(powerhook_desc) sfd_list; + void (*sfd_fn) __P((int, void *)); + void *sfd_arg; +}; + +LIST_HEAD(, powerhook_desc) powerhook_list; + +void * +powerhook_establish(fn, arg) + void (*fn) __P((int, void *)); + 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; + LIST_INSERT_HEAD(&powerhook_list, ndp, sfd_list); + + return (ndp); +} + +void +powerhook_disestablish(vhook) + void *vhook; +{ +#ifdef DIAGNOSTIC + struct powerhook_desc *dp; + + for (dp = powerhook_list.lh_first; dp != NULL; + dp = dp->sfd_list.le_next) + if (dp == vhook) + break; + if (dp == NULL) + panic("powerhook_disestablish: hook not established"); +#endif + + LIST_REMOVE((struct powerhook_desc *)vhook, sfd_list); + free(vhook, M_DEVBUF); +} + +/* + * Run power hooks. + */ +void +dopowerhooks(why) + int why; +{ + struct powerhook_desc *dp; + + for (dp = LIST_FIRST(&powerhook_list); + dp != NULL; + dp = LIST_NEXT(dp, sfd_list)) { + (*dp->sfd_fn)(why, dp->sfd_arg); + } +} diff --git a/sys/sys/systm.h b/sys/sys/systm.h index e9ac3597d82..c68a72ac109 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.32 1999/09/12 19:44:04 weingart Exp $ */ +/* $OpenBSD: systm.h,v 1.33 1999/11/07 17:39:14 provos Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -236,6 +236,16 @@ void *shutdownhook_establish __P((void (*)(void *), void *)); void shutdownhook_disestablish __P((void *)); void doshutdownhooks __P((void)); +/* + * Power managment hooks. + */ +void *powerhook_establish __P((void (*)(int, void *), void *)); +void powerhook_disestablish __P((void *)); +void dopowerhooks __P((int)); +#define PWR_RESUME 0 +#define PWR_SUSPEND 1 +#define PWR_STANDBY 2 + struct uio; int uiomove __P((caddr_t, int, struct uio *)); |