diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -102,6 +102,11 @@ int num; }; +struct acpi_wake_prep_context { + struct acpi_softc *sc; + enum power_stype stype; +}; + static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL }; /* Global mutex for locking access to the ACPI subsystem. */ @@ -175,10 +180,11 @@ static void acpi_shutdown_final(void *arg, int howto); static void acpi_enable_fixed_events(struct acpi_softc *sc); static void acpi_resync_clock(struct acpi_softc *sc); -static int acpi_wake_sleep_prep(ACPI_HANDLE handle, +static int acpi_wake_sleep_prep(struct acpi_softc *sc, ACPI_HANDLE handle, + enum power_stype stype); +static int acpi_wake_run_prep(struct acpi_softc *sc, ACPI_HANDLE handle, enum power_stype stype); -static int acpi_wake_run_prep(ACPI_HANDLE handle, enum power_stype stype); -static int acpi_wake_prep_walk(enum power_stype stype); +static int acpi_wake_prep_walk(struct acpi_softc *sc, enum power_stype stype); static int acpi_wake_sysctl_walk(device_t dev); static int acpi_wake_set_sysctl(SYSCTL_HANDLER_ARGS); static int acpi_supported_sleep_state_sysctl(SYSCTL_HANDLER_ARGS); @@ -865,6 +871,7 @@ static int acpi_shutdown(device_t dev) { + struct acpi_softc *sc = device_get_softc(dev); bus_topo_assert(); @@ -875,7 +882,7 @@ * Enable any GPEs that are able to power-on the system (i.e., RTC). * Also, disable any that are not valid for this state (most). */ - acpi_wake_prep_walk(ACPI_STATE_S5); + acpi_wake_prep_walk(sc, POWER_STYPE_POWEROFF); return (0); } @@ -3480,7 +3487,7 @@ sc->acpi_stype = stype; /* Enable any GPEs as appropriate and requested by the user. */ - acpi_wake_prep_walk(stype); + acpi_wake_prep_walk(sc, stype); slp_state = ACPI_SS_GPE_SET; /* @@ -3582,7 +3589,7 @@ if (slp_state >= ACPI_SS_SLP_PREP) resumeclock(); if (slp_state >= ACPI_SS_GPE_SET) { - acpi_wake_prep_walk(stype); + acpi_wake_prep_walk(sc, stype); sc->acpi_stype = POWER_STYPE_AWAKE; } if (slp_state >= ACPI_SS_DEV_SUSPEND) @@ -3674,19 +3681,18 @@ } static int -acpi_wake_sleep_prep(ACPI_HANDLE handle, enum power_stype stype) +acpi_wake_sleep_prep(struct acpi_softc *sc, ACPI_HANDLE handle, + enum power_stype stype) { int sstate; struct acpi_prw_data prw; device_t dev; - struct acpi_softc *sc; /* Check that this is a wake-capable device and get its GPE. */ if (acpi_parse_prw(handle, &prw) != 0) return (ENXIO); dev = acpi_get_device(handle); - sc = device_get_softc(dev); sstate = acpi_stype_to_sstate(sc, stype); /* @@ -3713,12 +3719,12 @@ } static int -acpi_wake_run_prep(ACPI_HANDLE handle, enum power_stype stype) +acpi_wake_run_prep(struct acpi_softc *sc, ACPI_HANDLE handle, + enum power_stype stype) { int sstate; struct acpi_prw_data prw; device_t dev; - struct acpi_softc *sc; /* * Check that this is a wake-capable device and get its GPE. Return @@ -3730,7 +3736,6 @@ if (dev == NULL || (acpi_get_flags(dev) & ACPI_FLAG_WAKE_ENABLED) == 0) return (0); - sc = device_get_softc(dev); sstate = acpi_stype_to_sstate(sc, stype); /* @@ -3756,26 +3761,30 @@ static ACPI_STATUS acpi_wake_prep(ACPI_HANDLE handle, UINT32 level, void *context, void **status) { - enum power_stype stype; + struct acpi_softc *sc = ((struct acpi_wake_prep_context *)context)->sc; + enum power_stype stype = ((struct acpi_wake_prep_context *)context)->stype; /* If suspending, run the sleep prep function, otherwise wake. */ - stype = *(enum power_stype *)context; if (AcpiGbl_SystemAwakeAndRunning) - acpi_wake_sleep_prep(handle, stype); + acpi_wake_sleep_prep(sc, handle, stype); else - acpi_wake_run_prep(handle, stype); + acpi_wake_run_prep(sc, handle, stype); return (AE_OK); } /* Walk the tree rooted at acpi0 to prep devices for suspend/resume. */ static int -acpi_wake_prep_walk(enum power_stype stype) +acpi_wake_prep_walk(struct acpi_softc *sc, enum power_stype stype) { ACPI_HANDLE sb_handle; + struct acpi_wake_prep_context ctx = { + .sc = sc, + .stype = stype, + }; if (ACPI_SUCCESS(AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &sb_handle))) AcpiWalkNamespace(ACPI_TYPE_DEVICE, sb_handle, 100, - acpi_wake_prep, NULL, &stype, NULL); + acpi_wake_prep, NULL, &ctx, NULL); return (0); }