From 33febf93d6e69967393353136a9e3a0829e1bd10 Mon Sep 17 00:00:00 2001 From: Nate Lawson Date: Wed, 11 Feb 2004 02:57:33 +0000 Subject: [PATCH] Prefer buttons defined in the AML over the ones in the FADT. Some systems define power/sleep buttons in both places but only deliver notifies to the ones defined in the AML. Also, reduce length of various function handler names. PR: Submitted by: Reviewed by: Approved by: Obtained from: MFC after: --- sys/dev/acpica/acpi.c | 14 +++++------- sys/dev/acpica/acpi_button.c | 44 ++++++++++++++++++++++++++---------- sys/dev/acpica/acpivar.h | 8 +++---- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index 856fad064480..0f81f2a60f11 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -1125,8 +1125,7 @@ acpi_enable_fixed_events(struct acpi_softc *sc) AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, 0); AcpiClearEvent(ACPI_EVENT_POWER_BUTTON); AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, - acpi_eventhandler_power_button_for_sleep, - sc); + acpi_event_power_button_sleep, sc); if (first_time) device_printf(sc->acpi_dev, "Power Button (fixed)\n"); } @@ -1134,8 +1133,7 @@ acpi_enable_fixed_events(struct acpi_softc *sc) AcpiEnableEvent(ACPI_EVENT_SLEEP_BUTTON, 0); AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON); AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON, - acpi_eventhandler_sleep_button_for_sleep, - sc); + acpi_event_sleep_button_sleep, sc); if (first_time) device_printf(sc->acpi_dev, "Sleep Button (fixed)\n"); } @@ -1719,7 +1717,7 @@ acpi_system_eventhandler_wakeup(void *arg, int state) * ACPICA Event Handlers (FixedEvent, also called from button notify handler) */ UINT32 -acpi_eventhandler_power_button_for_sleep(void *context) +acpi_event_power_button_sleep(void *context) { struct acpi_softc *sc = (struct acpi_softc *)context; @@ -1731,7 +1729,7 @@ acpi_eventhandler_power_button_for_sleep(void *context) } UINT32 -acpi_eventhandler_power_button_for_wakeup(void *context) +acpi_event_power_button_wake(void *context) { struct acpi_softc *sc = (struct acpi_softc *)context; @@ -1743,7 +1741,7 @@ acpi_eventhandler_power_button_for_wakeup(void *context) } UINT32 -acpi_eventhandler_sleep_button_for_sleep(void *context) +acpi_event_sleep_button_sleep(void *context) { struct acpi_softc *sc = (struct acpi_softc *)context; @@ -1755,7 +1753,7 @@ acpi_eventhandler_sleep_button_for_sleep(void *context) } UINT32 -acpi_eventhandler_sleep_button_for_wakeup(void *context) +acpi_event_sleep_button_wake(void *context) { struct acpi_softc *sc = (struct acpi_softc *)context; diff --git a/sys/dev/acpica/acpi_button.c b/sys/dev/acpica/acpi_button.c index 33ace7870f38..3bab1dde7e5e 100644 --- a/sys/dev/acpica/acpi_button.c +++ b/sys/dev/acpica/acpi_button.c @@ -60,8 +60,8 @@ static void acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context); static ACPI_STATUS acpi_button_fixed_handler(void *context); -static void acpi_button_notify_pressed_for_sleep(void *arg); -static void acpi_button_notify_pressed_for_wakeup(void *arg); +static void acpi_button_notify_sleep(void *arg); +static void acpi_button_notify_wakeup(void *arg); static device_method_t acpi_button_methods[] = { /* Device interface */ @@ -127,10 +127,13 @@ acpi_button_attach(device_t dev) sc = device_get_softc(dev); sc->button_dev = dev; sc->button_handle = acpi_get_handle(dev); + event = (sc->button_type == ACPI_SLEEP_BUTTON) ? + ACPI_EVENT_SLEEP_BUTTON : ACPI_EVENT_POWER_BUTTON; + /* Install the appropriate new handler. */ if (sc->fixed) { - event = (sc->button_type == ACPI_SLEEP_BUTTON) ? - ACPI_EVENT_SLEEP_BUTTON : ACPI_EVENT_POWER_BUTTON; + AcpiEnableEvent(event, 0); + AcpiClearEvent(event); status = AcpiInstallFixedEventHandler(event, acpi_button_fixed_handler, sc); } else { @@ -143,6 +146,23 @@ acpi_button_attach(device_t dev) return_VALUE (ENXIO); } acpi_device_enable_wake_capability(sc->button_handle, 1); + + /* + * If we have fixed buttons defined in the FADT, remove them now that + * we have found one in the AML. Some systems define buttons both ways + * but only deliver events to the AML object. + */ + if (event == ACPI_EVENT_POWER_BUTTON && AcpiGbl_FADT->PwrButton == 0) { + AcpiDisableEvent(event, 0); + AcpiClearEvent(event); + AcpiRemoveFixedEventHandler(event, acpi_event_power_button_sleep); + } + if (event == ACPI_EVENT_SLEEP_BUTTON && AcpiGbl_FADT->SleepButton == 0) { + AcpiDisableEvent(event, 0); + AcpiClearEvent(event); + AcpiRemoveFixedEventHandler(event, acpi_event_sleep_button_sleep); + } + return_VALUE (0); } @@ -163,7 +183,7 @@ acpi_button_resume(device_t dev) } static void -acpi_button_notify_pressed_for_sleep(void *arg) +acpi_button_notify_sleep(void *arg) { struct acpi_button_softc *sc; struct acpi_softc *acpi_sc; @@ -180,11 +200,11 @@ acpi_button_notify_pressed_for_sleep(void *arg) switch (sc->button_type) { case ACPI_POWER_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "power button pressed\n"); - acpi_eventhandler_power_button_for_sleep((void *)acpi_sc); + acpi_event_power_button_sleep(acpi_sc); break; case ACPI_SLEEP_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "sleep button pressed\n"); - acpi_eventhandler_sleep_button_for_sleep((void *)acpi_sc); + acpi_event_sleep_button_sleep(acpi_sc); break; default: break; /* unknown button type */ @@ -192,7 +212,7 @@ acpi_button_notify_pressed_for_sleep(void *arg) } static void -acpi_button_notify_pressed_for_wakeup(void *arg) +acpi_button_notify_wakeup(void *arg) { struct acpi_button_softc *sc; struct acpi_softc *acpi_sc; @@ -209,11 +229,11 @@ acpi_button_notify_pressed_for_wakeup(void *arg) switch (sc->button_type) { case ACPI_POWER_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "wakeup by power button\n"); - acpi_eventhandler_power_button_for_wakeup((void *)acpi_sc); + acpi_event_power_button_wake(acpi_sc); break; case ACPI_SLEEP_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "wakeup by sleep button\n"); - acpi_eventhandler_sleep_button_for_wakeup((void *)acpi_sc); + acpi_event_sleep_button_wake(acpi_sc); break; default: break; /* unknown button type */ @@ -230,11 +250,11 @@ acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context) switch (notify) { case ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP: AcpiOsQueueForExecution(OSD_PRIORITY_LO, - acpi_button_notify_pressed_for_sleep, sc); + acpi_button_notify_sleep, sc); break; case ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP: AcpiOsQueueForExecution(OSD_PRIORITY_LO, - acpi_button_notify_pressed_for_wakeup, sc); + acpi_button_notify_wakeup, sc); break; default: break; /* unknown notification value */ diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h index 13b7fa5ba258..4b64b07f5906 100644 --- a/sys/dev/acpica/acpivar.h +++ b/sys/dev/acpica/acpivar.h @@ -225,10 +225,10 @@ extern ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, #define ACPI_RESOURCE_NEXT(Res) (ACPI_RESOURCE *)((UINT8 *)Res + Res->Length) /* ACPI event handling */ -extern UINT32 acpi_eventhandler_power_button_for_sleep(void *context); -extern UINT32 acpi_eventhandler_power_button_for_wakeup(void *context); -extern UINT32 acpi_eventhandler_sleep_button_for_sleep(void *context); -extern UINT32 acpi_eventhandler_sleep_button_for_wakeup(void *context); +extern UINT32 acpi_event_power_button_sleep(void *context); +extern UINT32 acpi_event_power_button_wake(void *context); +extern UINT32 acpi_event_sleep_button_sleep(void *context); +extern UINT32 acpi_event_sleep_button_wake(void *context); #define ACPI_EVENT_PRI_FIRST 0 #define ACPI_EVENT_PRI_DEFAULT 10000