diff options
| author | thorpej <thorpej@NetBSD.org> | 2003-04-17 01:02:21 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 2003-04-17 01:02:21 +0000 |
| commit | b0f79c65ce645bb1a568b453d485eb67704d647b (patch) | |
| tree | 62f5616220db2b1625d4e65982a6d8ad1b99058d /sys/dev | |
| parent | 9871c6a16c4beacf75e521b379bbded95b5b37d9 (diff) | |
Start at a power management framework for sysmon. Right now we just
provide some VERY basic support for power/sleep buttons and lid switches;
if someone presses the power button, shut down the system semi-gracefully.
Eventually, we will send events for all types of button/lid events down
to a userland power management daemon, which will be able to define a
separate policy for each button/switch.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/sysmon/files.sysmon | 8 | ||||
| -rw-r--r-- | sys/dev/sysmon/sysmon_power.c | 166 | ||||
| -rw-r--r-- | sys/dev/sysmon/sysmonvar.h | 25 |
3 files changed, 196 insertions, 3 deletions
diff --git a/sys/dev/sysmon/files.sysmon b/sys/dev/sysmon/files.sysmon index d59062671a5..2e0deccbcfa 100644 --- a/sys/dev/sysmon/files.sysmon +++ b/sys/dev/sysmon/files.sysmon @@ -1,4 +1,4 @@ -# $NetBSD: files.sysmon,v 1.1 2002/04/16 21:00:29 thorpej Exp $ +# $NetBSD: files.sysmon,v 1.2 2003/04/17 01:02:21 thorpej Exp $ define sysmon_envsys file dev/sysmon/sysmon_envsys.c sysmon_envsys needs-flag @@ -6,4 +6,8 @@ file dev/sysmon/sysmon_envsys.c sysmon_envsys needs-flag define sysmon_wdog file dev/sysmon/sysmon_wdog.c sysmon_wdog needs-flag -file dev/sysmon/sysmon.c sysmon_envsys | sysmon_wdog +define sysmon_power +file dev/sysmon/sysmon_power.c sysmon_power needs-flag + +file dev/sysmon/sysmon.c sysmon_envsys | sysmon_wdog | + sysmon_power diff --git a/sys/dev/sysmon/sysmon_power.c b/sys/dev/sysmon/sysmon_power.c new file mode 100644 index 00000000000..7eceae58362 --- /dev/null +++ b/sys/dev/sysmon/sysmon_power.c @@ -0,0 +1,166 @@ +/* $NetBSD: sysmon_power.c,v 1.1 2003/04/17 01:02:21 thorpej Exp $ */ + +/* + * Copyright (c) 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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. + */ + +/* + * Power management framework for sysmon. + * + * We defer to a power management daemon running in userspace, since + * power management is largely a policy issue. This merely provides + * for power management event notification to that daemon. + */ + +#include <sys/param.h> +#include <sys/reboot.h> +#include <sys/systm.h> + +#include <dev/sysmon/sysmonvar.h> + +static LIST_HEAD(, sysmon_pswitch) sysmon_pswitch_list = + LIST_HEAD_INITIALIZER(sysmon_pswitch_list); +static struct simplelock sysmon_pswitch_list_slock = + SIMPLELOCK_INITIALIZER; + +static struct proc *sysmon_power_daemon; + +/* + * sysmon_pswitch_register: + * + * Register a power switch device. + */ +int +sysmon_pswitch_register(struct sysmon_pswitch *smpsw) +{ + + simple_lock(&sysmon_pswitch_list_slock); + LIST_INSERT_HEAD(&sysmon_pswitch_list, smpsw, smpsw_list); + simple_unlock(&sysmon_pswitch_list_slock); + + return (0); +} + +/* + * sysmon_pswitch_unregister: + * + * Unregister a power switch device. + */ +void +sysmon_pswitch_unregister(struct sysmon_pswitch *smpsw) +{ + + simple_lock(&sysmon_pswitch_list_slock); + LIST_REMOVE(smpsw, smpsw_list); + simple_unlock(&sysmon_pswitch_list_slock); +} + +/* + * sysmon_pswitch_event: + * + * Register an event on a power switch device. + */ +void +sysmon_pswitch_event(struct sysmon_pswitch *smpsw, int event) +{ + + /* + * If a power management daemon is connected, then simply + * deliver the event to them. If not, we need to try to + * do something reasonable ourselves. + */ + if (sysmon_power_daemon != NULL) { + /* XXX */ + return; + } + + switch (smpsw->smpsw_type) { + case SMPSW_TYPE_POWER: + if (event != SMPSW_EVENT_PRESSED) { + /* just ignore it */ + return; + } + + /* + * Attempt a somewhat graceful shutdown of the system, + * as if the user has issued a reboot(2) call with + * RB_POWERDOWN. + */ + printf("%s: power button pressed, shutting down!\n", + smpsw->smpsw_name); + cpu_reboot(RB_POWERDOWN, NULL); + break; + + case SMPSW_TYPE_SLEEP: + if (event != SMPSW_EVENT_PRESSED) { + /* just ignore it */ + return; + } + + /* + * Try to enter a "sleep" state. + */ + /* XXX */ + printf("%s: sleep button pressed.\n", smpsw->smpsw_name); + break; + + case SMPSW_TYPE_LID: + switch (event) { + case SMPSW_EVENT_PRESSED: + /* + * Try to enter a "standby" state. + */ + /* XXX */ + printf("%s: lid closed.\n", smpsw->smpsw_name); + break; + + case SMPSW_EVENT_RELEASED: + /* + * Come out of "standby" state. + */ + /* XXX */ + printf("%s: lid opened.\n", smpsw->smpsw_name); + break; + + default: + printf("%s: unknown lid switch event: %d\n", + smpsw->smpsw_name, event); + } + break; + + default: + printf("%s: sysmon_pswitch_event can't handle me.\n", + smpsw->smpsw_name); + } +} diff --git a/sys/dev/sysmon/sysmonvar.h b/sys/dev/sysmon/sysmonvar.h index 0ba348d666c..abf915cfc5c 100644 --- a/sys/dev/sysmon/sysmonvar.h +++ b/sys/dev/sysmon/sysmonvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: sysmonvar.h,v 1.4 2003/04/10 18:04:20 thorpej Exp $ */ +/* $NetBSD: sysmonvar.h,v 1.5 2003/04/17 01:02:21 thorpej Exp $ */ /*- * Copyright (c) 2000 Zembu Labs, Inc. @@ -101,4 +101,27 @@ int sysmonioctl_wdog(dev_t, u_long, caddr_t, int, struct proc *); int sysmon_wdog_register(struct sysmon_wdog *); void sysmon_wdog_unregister(struct sysmon_wdog *); +/***************************************************************************** + * Power management support + *****************************************************************************/ + +struct sysmon_pswitch { + const char *smpsw_name; /* power switch name */ + int smpsw_type; /* power switch type */ + + LIST_ENTRY(sysmon_pswitch) smpsw_list; +}; + +#define SMPSW_TYPE_POWER 0 /* power button */ +#define SMPSW_TYPE_SLEEP 1 /* sleep button */ +#define SMPSW_TYPE_LID 2 /* lid switch */ + +#define SMPSW_EVENT_PRESSED 0 /* button pressed/lid closed */ +#define SMPSW_EVENT_RELEASED 1 /* button released/lid opened */ + +int sysmon_pswitch_register(struct sysmon_pswitch *); +void sysmon_pswitch_unregister(struct sysmon_pswitch *); + +void sysmon_pswitch_event(struct sysmon_pswitch *, int); + #endif /* _DEV_SYSMON_SYSMONVAR_H_ */ |
