Changeset View
Standalone View
sys/dev/acpica/acpi.c
| Show First 20 Lines • Show All 3,741 Lines • ▼ Show 20 Lines | __unreachable(); | ||||
| */ | */ | ||||
| backout: | backout: | ||||
| if ((slp_state & ACPI_SS_GPE_SET) != 0) { | if ((slp_state & ACPI_SS_GPE_SET) != 0) { | ||||
| acpi_wake_prep_walk(sc, stype); | acpi_wake_prep_walk(sc, stype); | ||||
| sc->acpi_stype = POWER_STYPE_AWAKE; | sc->acpi_stype = POWER_STYPE_AWAKE; | ||||
| slp_state &= ~ACPI_SS_GPE_SET; | slp_state &= ~ACPI_SS_GPE_SET; | ||||
| } | } | ||||
| if ((slp_state & ACPI_SS_DEV_SUSPEND) != 0) { | if ((slp_state & ACPI_SS_DEV_SUSPEND) != 0) { | ||||
| /* | |||||
| * Record the resume time so a spurious power/sleep button press can be | |||||
| * ignored for a grace period afterward (see the comment before | |||||
| * ACPI_BUTTON_REPLAY_WINDOW). This must be taken before | |||||
| * DEVICE_RESUME(), which re-initializes the EC that replays the press. | |||||
| */ | |||||
| sc->acpi_resume_sbt = getsbinuptime(); | |||||
| EVENTHANDLER_INVOKE(acpi_pre_dev_resume, stype); | EVENTHANDLER_INVOKE(acpi_pre_dev_resume, stype); | ||||
| DEVICE_RESUME(root_bus); | DEVICE_RESUME(root_bus); | ||||
| slp_state &= ~ACPI_SS_DEV_SUSPEND; | slp_state &= ~ACPI_SS_DEV_SUSPEND; | ||||
| } | } | ||||
| if ((slp_state & ACPI_SS_SLP_PREP) != 0) { | if ((slp_state & ACPI_SS_SLP_PREP) != 0) { | ||||
| AcpiLeaveSleepState(acpi_sstate); | AcpiLeaveSleepState(acpi_sstate); | ||||
| slp_state &= ~ACPI_SS_SLP_PREP; | slp_state &= ~ACPI_SS_SLP_PREP; | ||||
| } | } | ||||
| Show All 24 Lines | thread_unlock(curthread); | ||||
| } | } | ||||
| #endif | #endif | ||||
| resume_all_fs(); | resume_all_fs(); | ||||
| resume_all_proc(); | resume_all_proc(); | ||||
| EVENTHANDLER_INVOKE(power_resume, stype); | EVENTHANDLER_INVOKE(power_resume, stype); | ||||
| /* Allow another sleep request after a while. */ | /* Allow another sleep request after a while. */ | ||||
| callout_schedule(&acpi_sleep_timer, hz * ACPI_MINIMUM_AWAKETIME); | callout_schedule(&acpi_sleep_timer, hz * ACPI_MINIMUM_AWAKETIME); | ||||
| /* Run /etc/rc.resume after we are back. */ | /* Run /etc/rc.resume after we are back. */ | ||||
olce: Seems too detailed. Please just say that we record the time after wakeup to be able to ignore… | |||||
| if (devctl_process_running()) | if (devctl_process_running()) | ||||
| acpi_UserNotify("Resume", ACPI_ROOT_OBJECT, stype); | acpi_UserNotify("Resume", ACPI_ROOT_OBJECT, stype); | ||||
| return_ACPI_STATUS (status); | return_ACPI_STATUS (status); | ||||
| } | } | ||||
| static void | static void | ||||
| acpi_resync_clock(struct acpi_softc *sc) | acpi_resync_clock(struct acpi_softc *sc) | ||||
| ▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | acpi_system_eventhandler_wakeup(struct acpi_softc *const sc, | ||||
| ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, stype); | ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, stype); | ||||
| /* Currently, nothing to do for wakeup. */ | /* Currently, nothing to do for wakeup. */ | ||||
| return_VOID; | return_VOID; | ||||
| } | } | ||||
| /* | /* | ||||
| * ACPICA Event Handlers (FixedEvent, also called from button notify handler) | * ACPICA Event Handlers (FixedEvent, also called from button notify handler) | ||||
| */ | */ | ||||
| /* | |||||
Done Inline Actions0x80 is not a sleep event. The spec calls it git_danielschaefer.me: 0x80 is not a sleep event. The spec calls it | |||||
Done Inline ActionsThe spec calls it "S0 Power/Sleep Button Pressed". "Sleep event" is my own terminology, it looks like it conveys the idea, but feel free to suggest something else/change it. olce: The spec calls it "S0 Power/Sleep Button Pressed". "Sleep event" is my own terminology, it… | |||||
Done Inline ActionsDone in the updated diff — now "S0 Power/Sleep Button Pressed" (0x80) vs "Device Wake" (0x02), per the spec; dropped "sleep event." Comment-only, no functional change. dteske: Done in the updated diff — now "S0 Power/Sleep Button Pressed" (0x80) vs "Device Wake" (0x02)… | |||||
| * Grace window after wakeup during which a power/sleep button press for suspend | |||||
| * is ignored. Some firmware wrongly reports the depress that caused the wakeup | |||||
| * as a sleep event (Notify 0x80 instead of the spec-required 0x02); honoring it | |||||
| * re-enters sleep immediately after resume. On the Framework Laptop 12 the | |||||
| * replayed event arrives within ~620 ms of the recorded resume time, so a | |||||
| * one-second window was chosen. See https://bugs.freebsd.org/296243 for the | |||||
| * traces, timing data, and analysis. | |||||
| */ | |||||
| #define ACPI_BUTTON_REPLAY_WINDOW SBT_1S | |||||
| static bool | |||||
| acpi_button_resume_replay(struct acpi_softc *sc, const char *which) | |||||
| { | |||||
| sbintime_t elapsed; | |||||
| if (sc->acpi_resume_sbt == 0) | |||||
| return (false); | |||||
| elapsed = getsbinuptime() - sc->acpi_resume_sbt; | |||||
| if (elapsed < 0 || elapsed >= ACPI_BUTTON_REPLAY_WINDOW) | |||||
| return (false); | |||||
| if (bootverbose) { | |||||
| device_printf(sc->acpi_dev, | |||||
| "ignoring %s button press %jd us after resume " | |||||
| "(firmware replayed the wake event)\n", | |||||
| which, (intmax_t)(elapsed / SBT_1US)); | |||||
| } | |||||
| return (true); | |||||
| } | |||||
| void | void | ||||
Done Inline ActionsAgain, seems pretty long and with some perhaps not that relevant information. How about something like (probably can be condensed even further): olce: Again, seems pretty long and with some perhaps not that relevant information.
How about… | |||||
| acpi_invoke_sleep_eventhandler(const enum power_stype *const stype) | acpi_invoke_sleep_eventhandler(const enum power_stype *const stype) | ||||
| { | { | ||||
| EVENTHANDLER_INVOKE(acpi_sleep_event, *stype); | EVENTHANDLER_INVOKE(acpi_sleep_event, *stype); | ||||
| } | } | ||||
| void | void | ||||
Done Inline ActionsI'd put this behind bootverbose, and I suspect we'd be happier with microsecond elapsed time.... imp: I'd put this behind bootverbose, and I suspect we'd be happier with microsecond elapsed time.... | |||||
Done Inline ActionsAgree -- I was questioning myself whether to leave it in but erred on embracing the value, though more than happy to hide it behind verbose boot and move to microsecond resolution dteske: Agree -- I was questioning myself whether to leave it in but erred on embracing the value… | |||||
| acpi_invoke_wake_eventhandler(const enum power_stype *const stype) | acpi_invoke_wake_eventhandler(const enum power_stype *const stype) | ||||
| { | { | ||||
| EVENTHANDLER_INVOKE(acpi_wakeup_event, *stype); | EVENTHANDLER_INVOKE(acpi_wakeup_event, *stype); | ||||
| } | } | ||||
| UINT32 | UINT32 | ||||
| acpi_event_power_button_sleep(struct acpi_softc *sc) | acpi_event_power_button_sleep(struct acpi_softc *sc) | ||||
| { | { | ||||
| ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||||
| #if defined(__amd64__) || defined(__i386__) | #if defined(__amd64__) || defined(__i386__) | ||||
| if (acpi_button_resume_replay(sc, "power")) | |||||
| return_VALUE (ACPI_INTERRUPT_HANDLED); | |||||
| if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER, | if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER, | ||||
Done Inline ActionsMust be before the #if defined(...) just above. olce: Must be before the `#if defined(...)` just above. | |||||
Done Inline ActionsWell, forget it, as other platforms anyway don't support suspend/resume, that could as well stay here. olce: Well, forget it, as other platforms anyway don't support suspend/resume, that could as well… | |||||
| (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler, | (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler, | ||||
| &sc->acpi_power_button_stype))) | &sc->acpi_power_button_stype))) | ||||
| return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||||
| #else | #else | ||||
| shutdown_nice(RB_POWEROFF); | shutdown_nice(RB_POWEROFF); | ||||
| #endif | #endif | ||||
| return_VALUE (ACPI_INTERRUPT_HANDLED); | return_VALUE (ACPI_INTERRUPT_HANDLED); | ||||
| Show All 10 Lines | acpi_event_power_button_wake(struct acpi_softc *sc) | ||||
| return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||||
| return_VALUE (ACPI_INTERRUPT_HANDLED); | return_VALUE (ACPI_INTERRUPT_HANDLED); | ||||
| } | } | ||||
| UINT32 | UINT32 | ||||
| acpi_event_sleep_button_sleep(struct acpi_softc *sc) | acpi_event_sleep_button_sleep(struct acpi_softc *sc) | ||||
| { | { | ||||
| ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||||
| if (acpi_button_resume_replay(sc, "sleep")) | |||||
| return_VALUE (ACPI_INTERRUPT_HANDLED); | |||||
| if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER, | if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER, | ||||
| (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler, | (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler, | ||||
| &sc->acpi_sleep_button_stype))) | &sc->acpi_sleep_button_stype))) | ||||
| return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); | ||||
| return_VALUE (ACPI_INTERRUPT_HANDLED); | return_VALUE (ACPI_INTERRUPT_HANDLED); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 849 Lines • Show Last 20 Lines | |||||
Seems too detailed. Please just say that we record the time after wakeup to be able to ignore spurious sleep events for a grace period. The precise details of the mechanism, in particular the functions realizing it, is too level and may change without the comment being updated. Refer to the herald comment before ACPI_BUTTON_REPLAY_WINDOW.