diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2010-03-31 19:21:20 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2010-03-31 19:21:20 +0000 |
commit | 86522847c512d0f481c13afd50a8e1884a8551fa (patch) | |
tree | 384c18bf228bf1183eadb20ed60c3d2dacde33fb /sys/dev/acpi | |
parent | 03e578ef63dc46b1899f59c7405261b7e16e76bd (diff) |
Bring /dev/apm support in line with apm(4). Make the suspend button send
a suspend request event to apmd(8) instead of suspending immediately. Also
keep track of whether /dev/apm and /dev/apmctl are currently open, such that
we can still suspend immediately if apmd(8) isn't running.
ok deraadt@, marco@, pirofti@, jsing@, oga@
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r-- | sys/dev/acpi/acpi.c | 36 | ||||
-rw-r--r-- | sys/dev/acpi/acpibtn.c | 12 | ||||
-rw-r--r-- | sys/dev/acpi/acpivar.h | 10 |
3 files changed, 44 insertions, 14 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 3d7361a2ddf..15c83596401 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.154 2010/03/30 17:40:55 oga Exp $ */ +/* $OpenBSD: acpi.c,v 1.155 2010/03/31 19:21:19 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> @@ -892,23 +892,31 @@ acpiopen(dev_t dev, int flag, int mode, struct proc *p) !(sc = acpi_cd.cd_devs[APMUNIT(dev)])) return (ENXIO); + ACPI_LOCK(sc); switch (APMDEV(dev)) { case APMDEV_CTL: if (!(flag & FWRITE)) { error = EINVAL; break; } + if (sc->sc_flags & SCFLAG_OWRITE) { + error = EBUSY; + break; + } + sc->sc_flags |= SCFLAG_OWRITE; break; case APMDEV_NORMAL: if (!(flag & FREAD) || (flag & FWRITE)) { error = EINVAL; break; } + sc->sc_flags |= SCFLAG_OREAD; break; default: error = ENXIO; break; } + ACPI_UNLOCK(sc); #else error = ENXIO; #endif @@ -926,14 +934,19 @@ acpiclose(dev_t dev, int flag, int mode, struct proc *p) !(sc = acpi_cd.cd_devs[APMUNIT(dev)])) return (ENXIO); + ACPI_LOCK(sc); switch (APMDEV(dev)) { case APMDEV_CTL: + sc->sc_flags &= ~SCFLAG_OWRITE; + break; case APMDEV_NORMAL: + sc->sc_flags &= ~SCFLAG_OREAD; break; default: error = ENXIO; break; } + ACPI_UNLOCK(sc); #else error = ENXIO; #endif @@ -959,8 +972,6 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) ACPI_LOCK(sc); /* fake APM */ switch (cmd) { - case APM_IOC_STANDBY_REQ: - case APM_IOC_SUSPEND_REQ: case APM_IOC_SUSPEND: case APM_IOC_STANDBY: /* @@ -1960,12 +1971,25 @@ acpi_resume(struct acpi_softc *sc, int state) aml_evalnode(sc, sc->sc_sst, 1, &env, NULL); } + acpi_record_event(sc, APM_NORMAL_RESUME); + #if NWSDISPLAY > 0 wsdisplay_resume(); #endif /* NWSDISPLAY > 0 */ } #endif /* ! SMALL_KERNEL */ +int +acpi_record_event(struct acpi_softc *sc, u_int type) +{ + if ((sc->sc_flags & SCFLAG_OPEN) == 0) + return (1); + + acpi_evindex++; + KNOTE(sc->sc_note, APM_EVENT_COMPOSE(type, acpi_evindex)); + return (0); +} + void acpi_handle_suspend_failure(struct acpi_softc *sc) { @@ -2140,20 +2164,14 @@ acpi_isr_thread(void *arg) aml_notify_dev(ACPI_DEV_PBD, 0x80); - acpi_evindex++; dnprintf(1,"power button pressed\n"); - KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_PWRBTN, - acpi_evindex)); } if (sc->sc_sleepbtn) { sc->sc_sleepbtn = 0; aml_notify_dev(ACPI_DEV_SBD, 0x80); - acpi_evindex++; dnprintf(1,"sleep button pressed\n"); - KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_SLPBTN, - acpi_evindex)); } /* handle polling here to keep code non-concurrent*/ diff --git a/sys/dev/acpi/acpibtn.c b/sys/dev/acpi/acpibtn.c index 09643d620c3..548dd3c800d 100644 --- a/sys/dev/acpi/acpibtn.c +++ b/sys/dev/acpi/acpibtn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpibtn.c,v 1.25 2009/12/05 04:20:58 deraadt Exp $ */ +/* $OpenBSD: acpibtn.c,v 1.26 2010/03/31 19:21:19 kettenis Exp $ */ /* * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org> * @@ -23,6 +23,7 @@ #include <sys/malloc.h> #include <machine/bus.h> +#include <machine/apmvar.h> #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> @@ -135,8 +136,10 @@ acpibtn_notify(struct aml_node *node, int notify_type, void *arg) "_LID", 0, NULL, &lid)) return (0); #if 0 - if (lid == 0) - acpi_sleep_state(sc->sc_acpi, ACPI_STATE_S3); + if (lid == 0) { + if (acpi_record_event(sc->sc_acpi, APM_USER_SUSPEND_REQ)) + acpi_sleep_state(sc->sc_acpi, ACPI_STATE_S3); + } #endif break; #endif /* SMALL_KERNEL */ @@ -148,7 +151,8 @@ acpibtn_notify(struct aml_node *node, int notify_type, void *arg) break; case 0x80: /* Request to go to sleep */ - acpi_sleep_state(sc->sc_acpi, ACPI_STATE_S3); + if (acpi_record_event(sc->sc_acpi, APM_USER_SUSPEND_REQ)) + acpi_sleep_state(sc->sc_acpi, ACPI_STATE_S3); break; } #endif /* SMALL_KERNEL */ diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 7d44290b6a0..32dca939a39 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.55 2009/11/26 23:44:38 mlarkin Exp $ */ +/* $OpenBSD: acpivar.h,v 1.56 2010/03/31 19:21:19 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * @@ -239,8 +239,14 @@ struct acpi_softc { int sc_revision; int sc_pse; /* passive cooling enabled */ + + int sc_flags; }; +#define SCFLAG_OREAD 0x0000001 +#define SCFLAG_OWRITE 0x0000002 +#define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) + #define GPE_NONE 0x00 #define GPE_LEVEL 0x01 #define GPE_EDGE 0x02 @@ -313,6 +319,8 @@ void acpi_poll(void *); int acpi_matchhids(struct acpi_attach_args *, const char *[], const char *); +int acpi_record_event(struct acpi_softc *, u_int); + #endif #endif /* !_ACPI_WAKECODE */ |