Skip to content

Commit ffdfca5

Browse files
committed
acpi: Factor out the power off code into acpi_poweroff()
While here, make it print that we are trying to power off upfront, not really treating differently power off preparation via acpi_EnterSleepStatePrep() and actual power off via AcpiEnterSleepState(), which the user does not care about. While here, capitalize the messages. Reviewed by: obiwac MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D55226
1 parent 781c9b0 commit ffdfca5

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

sys/dev/acpica/acpi.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,11 +2610,37 @@ acpi_EnterSleepStatePrep(device_t acpi_dev, UINT8 SleepState)
26102610
return (status);
26112611
}
26122612

2613+
/* Return from this function indicates failure. */
2614+
static void
2615+
acpi_poweroff(device_t acpi_dev)
2616+
{
2617+
register_t intr;
2618+
ACPI_STATUS status;
2619+
2620+
device_printf(acpi_dev, "Powering system off...\n");
2621+
status = acpi_EnterSleepStatePrep(acpi_dev, ACPI_STATE_S5);
2622+
if (ACPI_FAILURE(status)) {
2623+
device_printf(acpi_dev, "Power-off preparation failed! - %s\n",
2624+
AcpiFormatException(status));
2625+
return;
2626+
}
2627+
intr = intr_disable();
2628+
status = AcpiEnterSleepState(ACPI_STATE_S5);
2629+
if (ACPI_FAILURE(status)) {
2630+
intr_restore(intr);
2631+
device_printf(acpi_dev, "Power-off failed! - %s\n",
2632+
AcpiFormatException(status));
2633+
} else {
2634+
DELAY(1000000);
2635+
intr_restore(intr);
2636+
device_printf(acpi_dev, "Power-off failed! - timeout\n");
2637+
}
2638+
}
2639+
26132640
static void
26142641
acpi_shutdown_final(void *arg, int howto)
26152642
{
26162643
struct acpi_softc *sc = (struct acpi_softc *)arg;
2617-
register_t intr;
26182644
ACPI_STATUS status;
26192645

26202646
/*
@@ -2623,24 +2649,7 @@ acpi_shutdown_final(void *arg, int howto)
26232649
* an AP.
26242650
*/
26252651
if ((howto & RB_POWEROFF) != 0) {
2626-
status = acpi_EnterSleepStatePrep(sc->acpi_dev, ACPI_STATE_S5);
2627-
if (ACPI_FAILURE(status)) {
2628-
device_printf(sc->acpi_dev, "Power-off preparation failed! - %s\n",
2629-
AcpiFormatException(status));
2630-
return;
2631-
}
2632-
device_printf(sc->acpi_dev, "Powering system off\n");
2633-
intr = intr_disable();
2634-
status = AcpiEnterSleepState(ACPI_STATE_S5);
2635-
if (ACPI_FAILURE(status)) {
2636-
intr_restore(intr);
2637-
device_printf(sc->acpi_dev, "power-off failed - %s\n",
2638-
AcpiFormatException(status));
2639-
} else {
2640-
DELAY(1000000);
2641-
intr_restore(intr);
2642-
device_printf(sc->acpi_dev, "power-off failed - timeout\n");
2643-
}
2652+
acpi_poweroff(sc->acpi_dev);
26442653
} else if ((howto & RB_HALT) == 0 && sc->acpi_handle_reboot) {
26452654
/* Reboot using the reset register. */
26462655
status = AcpiReset();

0 commit comments

Comments
 (0)