diff options
author | jhb <jhb@FreeBSD.org> | 2001-01-13 21:28:57 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2001-01-13 21:28:57 +0000 |
commit | 2da785b10fc3ab93514921c99868995fcc14b753 (patch) | |
tree | 36a738c28a1f2e4dc89dcf71d24995e012943b65 /sys/dev/acpica | |
parent | 6a1d7a734cceb0a37a2f20a44022da576a9d6792 (diff) | |
download | FreeBSD-src-2da785b10fc3ab93514921c99868995fcc14b753.zip FreeBSD-src-2da785b10fc3ab93514921c99868995fcc14b753.tar.gz |
Add 3 new dynamic sysctl's to control the sleep states switched to on a
power button, sleep button, or lid close event. The sysctl's use the
ACPI sleep state names S0, S1, S2, S3, S4, S4B, and S5.
Reviewed by: iwasaki
Diffstat (limited to 'sys/dev/acpica')
-rw-r--r-- | sys/dev/acpica/acpi.c | 50 | ||||
-rw-r--r-- | sys/dev/acpica/acpivar.h | 3 |
2 files changed, 53 insertions, 0 deletions
diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index 4eac94b..2e627da 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -84,6 +84,9 @@ static struct cdevsw acpi_cdevsw = { -1 }; +static const char* sleep_state_names[] = { + "S0", "S1", "S2", "S3", "S4", "S4B", "S5" }; + static void acpi_identify(driver_t *driver, device_t parent); static int acpi_probe(device_t dev); static int acpi_attach(device_t dev); @@ -115,6 +118,7 @@ static void acpi_set_debugging(void); static void acpi_system_eventhandler_sleep(void *arg, int state); static void acpi_system_eventhandler_wakeup(void *arg, int state); +static int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS); static device_method_t acpi_methods[] = { /* Device interface */ @@ -301,6 +305,25 @@ acpi_attach(device_t dev) } /* + * Setup our sysctl tree. + * + * XXX: This doesn't check to make sure that none of these fail. + */ + sysctl_ctx_init(&sc->acpi_sysctl_ctx); + sc->acpi_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_sysctl_ctx, + SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO, + device_get_name(dev), CTLFLAG_RD, 0, ""); + SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree), + OID_AUTO, "power_button_state", CTLTYPE_STRING | CTLFLAG_RW, + &sc->acpi_power_button_sx, 0, acpi_sleep_state_sysctl, "A", ""); + SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree), + OID_AUTO, "sleep_button_state", CTLTYPE_STRING | CTLFLAG_RW, + &sc->acpi_sleep_button_sx, 0, acpi_sleep_state_sysctl, "A", ""); + SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree), + OID_AUTO, "lid_switch_state", CTLTYPE_STRING | CTLFLAG_RW, + &sc->acpi_lid_switch_sx, 0, acpi_sleep_state_sysctl, "A", ""); + + /* * Dispatch the default sleep state to devices. * TBD: should be configured from userland policy manager. */ @@ -1194,6 +1217,33 @@ out: return(error); } +static int +acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS) +{ + char sleep_state[10]; + int error; + u_int new_state, old_state; + + old_state = *(u_int *)oidp->oid_arg1; + if (old_state > ACPI_STATE_S5) + strcpy(sleep_state, "unknown"); + else + strncpy(sleep_state, sleep_state_names[old_state], + sizeof(sleep_state_names[old_state])); + error = sysctl_handle_string(oidp, sleep_state, sizeof(sleep_state), req); + if (error == 0 && req->newptr != NULL) { + for (new_state = ACPI_STATE_S0; new_state <= ACPI_STATE_S5; new_state++) + if (strncmp(sleep_state, sleep_state_names[new_state], + sizeof(sleep_state)) == 0) + break; + if (new_state != old_state && new_state <= ACPI_STATE_S5) + *(u_int *)oidp->oid_arg1 = new_state; + else + error = EINVAL; + } + return(error); +} + #ifdef ACPI_DEBUG /* * Support for parsing debug options from the kernel environment. diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h index 960d175..1b27e83 100644 --- a/sys/dev/acpica/acpivar.h +++ b/sys/dev/acpica/acpivar.h @@ -30,6 +30,7 @@ #include "bus_if.h" #include <sys/eventhandler.h> +#include <sys/sysctl.h> extern devclass_t acpi_devclass; @@ -44,6 +45,8 @@ struct acpi_softc { int acpi_enabled; int acpi_sstate; + struct sysctl_ctx_list acpi_sysctl_ctx; + struct sysctl_oid *acpi_sysctl_tree; #define ACPI_POWER_BUTTON_DEFAULT_SX ACPI_STATE_S5; #define ACPI_SLEEP_BUTTON_DEFAULT_SX ACPI_STATE_S1; #define ACPI_LID_SWITCH_DEFAULT_SX ACPI_STATE_S1; |