summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/apmd.conf4
-rwxr-xr-xetc/rc.resume16
-rwxr-xr-xetc/rc.suspend18
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.89
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.c26
5 files changed, 62 insertions, 11 deletions
diff --git a/etc/apmd.conf b/etc/apmd.conf
index 4dc79be..6726730 100644
--- a/etc/apmd.conf
+++ b/etc/apmd.conf
@@ -4,7 +4,7 @@
#
apm_event SUSPENDREQ {
- exec "/etc/rc.suspend";
+ exec "/etc/rc.suspend apm suspend";
}
apm_event USERSUSPENDREQ {
@@ -14,7 +14,7 @@ apm_event USERSUSPENDREQ {
}
apm_event NORMRESUME, STANDBYRESUME {
- exec "/etc/rc.resume";
+ exec "/etc/rc.resume apm resume";
}
# resume event configuration for serial mouse users by
diff --git a/etc/rc.resume b/etc/rc.resume
index ee1b82c..84aa022 100755
--- a/etc/rc.resume
+++ b/etc/rc.resume
@@ -29,10 +29,18 @@
# sample run command file for APM Resume Event
+if [ $# -ne 2 ]; then
+ echo "Usage: $0 [apm|acpi] [resume|1-5]"
+ exit 1
+fi
+
+subsystem=$1
+state=$2
+
if [ -r /var/run/rc.suspend.pid ]; then
kill -9 `cat /var/run/rc.suspend.pid`
rm -f /var/run/rc.suspend.pid
- echo 'rc.suspend is killed'
+ echo 'rc.resume: killed rc.suspend that was still around'
fi
# Turns on a power supply of a card in the slot inactivated.
@@ -40,7 +48,11 @@ fi
# pccardq | awk -F '~' '$5 == "inactive" \
# { printf("pccardc power %d 1", $1); }' | sh
-logger -t apmd resumed at `date +'%Y%m%d %H:%M:%S'`
+# UHCI has trouble resuming so we just load/unload it. You
+# should add any other kernel modules you want reloaded here.
+# kldload usb
+
+logger -t $subsystem resumed at `date +'%Y%m%d %H:%M:%S'`
sync && sync && sync
exit 0
diff --git a/etc/rc.suspend b/etc/rc.suspend
index 8b3e4fa..8b02a0f 100755
--- a/etc/rc.suspend
+++ b/etc/rc.suspend
@@ -29,6 +29,14 @@
# sample run command file for APM Suspend Event
+if [ $# -ne 2 ]; then
+ echo "Usage: $0 [apm|acpi] [standby,suspend|1-5]"
+ exit 1
+fi
+
+subsystem=$1
+state=$2
+
if [ -r /var/run/rc.suspend.pid ]; then
exit 1
fi
@@ -40,11 +48,15 @@ echo $$ > /var/run/rc.suspend.pid
# pccardq | awk -F '~' '$5 == "filled" && $4 ~ /sio/ \
# { printf("pccardc power %d 0", $1); }' | sh
-logger -t apmd suspend at `date +'%Y%m%d %H:%M:%S'`
+# UHCI has trouble resuming so we just load/unload it. You
+# should add any other kernel modules you want unloaded here.
+# kldunload usb
+
+logger -t $subsystem suspend at `date +'%Y%m%d %H:%M:%S'`
sync && sync && sync
-sleep 3
+[ $subsystem = "apm" ] && sleep 3
rm -f /var/run/rc.suspend.pid
-zzz
+[ $subsystem = "apm" ] && zzz
exit 0
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8
index 47f90c8..b3d8bd3 100644
--- a/usr.sbin/acpi/acpiconf/acpiconf.8
+++ b/usr.sbin/acpi/acpiconf/acpiconf.8
@@ -58,7 +58,8 @@ Enters the specified sleep mode.
Recognized types are
.Cm 1
(only the CPU clock is stopped),
-.Cm 2 ,
+.Cm 2
+(not implemented on most systems but similar to S1),
.Cm 3
(the CPU context is lost and memory context is preserved),
.Cm 4
@@ -69,6 +70,12 @@ and
Sleep states may also be given as S1, S2, etc.
The supported states depend on BIOS implementation, including ACPI
byte code (AML).
+If the
+.Pa /etc/rc.suspend
+and
+.Pa /etc/rc.resume
+scripts are executable, they will be run before and after entering
+the given sleep state.
.El
.Sh SEE ALSO
.Xr acpi 4 ,
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
index 9be6ad8..377f0f9 100644
--- a/usr.sbin/acpi/acpiconf/acpiconf.c
+++ b/usr.sbin/acpi/acpiconf/acpiconf.c
@@ -37,10 +37,11 @@
#include <unistd.h>
#include <dev/acpica/acpiio.h>
-
#include <contrib/dev/acpica/acpi.h>
-#define ACPIDEV "/dev/acpi"
+#define ACPIDEV "/dev/acpi"
+#define RC_SUSPEND_PATH "/etc/rc.suspend"
+#define RC_RESUME_PATH "/etc/rc.resume"
static int acpifd;
@@ -68,7 +69,26 @@ acpi_enable_disable(int enable)
static int
acpi_sleep(int sleep_type)
{
- if (ioctl(acpifd, ACPIIO_SETSLPSTATE, &sleep_type) == -1)
+ char cmd[64];
+ int ret;
+
+ /* Run the suspend rc script, if available. */
+ if (access(RC_SUSPEND_PATH, X_OK) == 0) {
+ snprintf(cmd, sizeof(cmd), "%s acpi %d", RC_SUSPEND_PATH,
+ sleep_type);
+ system(cmd);
+ }
+
+ ret = ioctl(acpifd, ACPIIO_SETSLPSTATE, &sleep_type);
+
+ /* Run the resume rc script, if available. */
+ if (access(RC_RESUME_PATH, X_OK) == 0) {
+ snprintf(cmd, sizeof(cmd), "%s acpi %d", RC_RESUME_PATH,
+ sleep_type);
+ system(cmd);
+ }
+
+ if (ret != 0)
err(EX_IOERR, "sleep type (%d) failed", sleep_type);
return (0);
OpenPOWER on IntegriCloud