From 8a0aee6c29f5baec086d022bd084cdf14fdf6155 Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 13 May 2024 19:56:37 +0000 Subject: [PATCH] Ignore button events in the first 10 seconds after resume. On some ACPI implementations pressing the power button to wake up a machine will cause a power button notification to happen for that button press This would initiate a power down, which isn't the user's intent. Based on earlier diffs from deraadt@ and James Cook. ok mlarkin@, "I'm not opposed" cheloha@ --- sys/dev/acpi/acpi.c | 12 +++++++++++- sys/dev/acpi/acpi_x86.c | 4 +++- sys/dev/acpi/acpibtn.c | 6 +++++- sys/dev/acpi/acpivar.h | 4 +++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index da142b610cf..f53c84e143c 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.427 2024/05/13 01:15:50 jsg Exp $ */ +/* $OpenBSD: acpi.c,v 1.428 2024/05/13 19:56:37 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -1963,6 +1963,12 @@ acpi_sleep_task(void *arg0, int sleepmode) #endif /* SMALL_KERNEL */ +int +acpi_resuming(struct acpi_softc *sc) +{ + return (getuptime() < sc->sc_resume_time + 10); +} + void acpi_reset(void) { @@ -2029,6 +2035,10 @@ acpi_pbtn_task(void *arg0, int dummy) en | ACPI_PM1_PWRBTN_EN); splx(s); + /* Ignore button events if we're resuming. */ + if (acpi_resuming(sc)) + return; + switch (pwr_action) { case 0: break; diff --git a/sys/dev/acpi/acpi_x86.c b/sys/dev/acpi/acpi_x86.c index b9f19fdb7d1..5150fb11f97 100644 --- a/sys/dev/acpi/acpi_x86.c +++ b/sys/dev/acpi/acpi_x86.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_x86.c,v 1.17 2023/07/06 06:58:07 deraadt Exp $ */ +/* $OpenBSD: acpi_x86.c,v 1.18 2024/05/13 19:56:37 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -114,6 +114,8 @@ sleep_resume(void *v) { struct acpi_softc *sc = v; + sc->sc_resume_time = getuptime(); + acpibtn_disable_psw(); /* disable _LID for wakeup */ /* 3rd resume AML step: _TTS(runstate) */ diff --git a/sys/dev/acpi/acpibtn.c b/sys/dev/acpi/acpibtn.c index 373f05e1377..bda94a9a4e1 100644 --- a/sys/dev/acpi/acpibtn.c +++ b/sys/dev/acpi/acpibtn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpibtn.c,v 1.51 2023/06/29 20:58:08 dv Exp $ */ +/* $OpenBSD: acpibtn.c,v 1.52 2024/05/13 19:56:37 kettenis Exp $ */ /* * Copyright (c) 2005 Marco Peereboom * @@ -229,6 +229,10 @@ acpibtn_notify(struct aml_node *node, int notify_type, void *arg) dnprintf(10, "acpibtn_notify: %.2x %s\n", notify_type, sc->sc_devnode->name); + /* Ignore button events if we're resuming. */ + if (acpi_resuming(sc->sc_acpi)) + return (0); + switch (sc->sc_btn_type) { case ACPIBTN_LID: #ifndef SMALL_KERNEL diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 083226b531e..b29c9a6b30e 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.126 2024/05/13 01:15:50 jsg Exp $ */ +/* $OpenBSD: acpivar.h,v 1.127 2024/05/13 19:56:37 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -269,6 +269,7 @@ struct acpi_softc { struct aml_node *sc_sst; struct aml_node *sc_wak; int sc_state; + time_t sc_resume_time; struct acpiec_softc *sc_ec; /* XXX assume single EC */ struct acpi_ac_head sc_ac; @@ -340,6 +341,7 @@ int acpi_sleep_cpu(struct acpi_softc *, int); void acpi_sleep_pm(struct acpi_softc *, int); void acpi_resume_pm(struct acpi_softc *, int); void acpi_resume_cpu(struct acpi_softc *, int); +int acpi_resuming(struct acpi_softc *); #define ACPI_IOREAD 0 #define ACPI_IOWRITE 1 -- 2.20.1