aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Certner <olce@FreeBSD.org>2026-06-04 09:48:33 +0000
committerOlivier Certner <olce@FreeBSD.org>2026-06-22 21:40:13 +0000
commit660a491c41a2b90c35fe121c0b6a046b9af3cc00 (patch)
tree6dd247b99e1a372d8987f3660c8d20b9b0f4e126
parent3b3911aaf834824f2de0db9fc7d0b9e2b3c089b4 (diff)
acpi: Button sleep/wake callbacks: Expose true argument types
This makes the interface composed of the acpi_event_{power,sleep}_button_{sleep,wake}() functions more accurate and clears the risk of calling them with a wrong object (such as a wrong softc). Reviewed by: obiwac Event: Halifax Hackathon 202606 Sponsored by: The FreeBSD Foundation Pull Request: https://github.com/OlCe2/freebsd-src/pull/8
-rw-r--r--sys/dev/acpica/acpi.c48
-rw-r--r--sys/dev/acpica/acpivar.h8
2 files changed, 23 insertions, 33 deletions
diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index d599094718f7..91913c1daa60 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -2701,14 +2701,14 @@ acpi_enable_fixed_events(struct acpi_softc *sc)
if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) {
AcpiClearEvent(ACPI_EVENT_POWER_BUTTON);
AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON,
- acpi_event_power_button_sleep, sc);
+ (ACPI_EVENT_HANDLER)acpi_event_power_button_sleep, sc);
if (first_time)
device_printf(sc->acpi_dev, "Power Button (fixed)\n");
}
if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON);
AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON,
- acpi_event_sleep_button_sleep, sc);
+ (ACPI_EVENT_HANDLER)acpi_event_sleep_button_sleep, sc);
if (first_time)
device_printf(sc->acpi_dev, "Sleep Button (fixed)\n");
}
@@ -4141,37 +4141,30 @@ acpi_system_eventhandler_wakeup(void *arg, enum power_stype stype)
return_VOID;
}
-/*
+/*
* ACPICA Event Handlers (FixedEvent, also called from button notify handler)
*/
static void
-acpi_invoke_sleep_eventhandler(void *context)
+acpi_invoke_sleep_eventhandler(const enum power_stype *const stype)
{
-
- EVENTHANDLER_INVOKE(acpi_sleep_event, *(enum power_stype *)context);
+ EVENTHANDLER_INVOKE(acpi_sleep_event, *stype);
}
static void
-acpi_invoke_wake_eventhandler(void *context)
+acpi_invoke_wake_eventhandler(const enum power_stype *const stype)
{
-
- EVENTHANDLER_INVOKE(acpi_wakeup_event, *(enum power_stype *)context);
+ EVENTHANDLER_INVOKE(acpi_wakeup_event, *stype);
}
UINT32
-acpi_event_power_button_sleep(void *context)
+acpi_event_power_button_sleep(struct acpi_softc *sc)
{
-#if defined(__amd64__) || defined(__i386__)
- struct acpi_softc *sc = (struct acpi_softc *)context;
-#else
- (void)context;
-#endif
-
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
#if defined(__amd64__) || defined(__i386__)
if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER,
- acpi_invoke_sleep_eventhandler, &sc->acpi_power_button_stype)))
+ (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler,
+ &sc->acpi_power_button_stype)))
return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
#else
shutdown_nice(RB_POWEROFF);
@@ -4181,40 +4174,37 @@ acpi_event_power_button_sleep(void *context)
}
UINT32
-acpi_event_power_button_wake(void *context)
+acpi_event_power_button_wake(struct acpi_softc *sc)
{
- struct acpi_softc *sc = (struct acpi_softc *)context;
-
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER,
- acpi_invoke_wake_eventhandler, &sc->acpi_power_button_stype)))
+ (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_wake_eventhandler,
+ &sc->acpi_power_button_stype)))
return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
return_VALUE (ACPI_INTERRUPT_HANDLED);
}
UINT32
-acpi_event_sleep_button_sleep(void *context)
+acpi_event_sleep_button_sleep(struct acpi_softc *sc)
{
- struct acpi_softc *sc = (struct acpi_softc *)context;
-
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER,
- acpi_invoke_sleep_eventhandler, &sc->acpi_sleep_button_stype)))
+ (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_sleep_eventhandler,
+ &sc->acpi_sleep_button_stype)))
return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
return_VALUE (ACPI_INTERRUPT_HANDLED);
}
UINT32
-acpi_event_sleep_button_wake(void *context)
+acpi_event_sleep_button_wake(struct acpi_softc *sc)
{
- struct acpi_softc *sc = (struct acpi_softc *)context;
-
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
if (ACPI_FAILURE(AcpiOsExecute(OSL_NOTIFY_HANDLER,
- acpi_invoke_wake_eventhandler, &sc->acpi_sleep_button_stype)))
+ (ACPI_OSD_EXEC_CALLBACK)acpi_invoke_wake_eventhandler,
+ &sc->acpi_sleep_button_stype)))
return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
return_VALUE (ACPI_INTERRUPT_HANDLED);
}
diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h
index 5d1415a8f543..aa30e5fef26e 100644
--- a/sys/dev/acpica/acpivar.h
+++ b/sys/dev/acpica/acpivar.h
@@ -457,10 +457,10 @@ ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
struct acpi_parse_resource_set *set, void *arg);
/* ACPI event handling */
-UINT32 acpi_event_power_button_sleep(void *context);
-UINT32 acpi_event_power_button_wake(void *context);
-UINT32 acpi_event_sleep_button_sleep(void *context);
-UINT32 acpi_event_sleep_button_wake(void *context);
+UINT32 acpi_event_power_button_sleep(struct acpi_softc *sc);
+UINT32 acpi_event_power_button_wake(struct acpi_softc *sc);
+UINT32 acpi_event_sleep_button_sleep(struct acpi_softc *sc);
+UINT32 acpi_event_sleep_button_wake(struct acpi_softc *sc);
#define ACPI_EVENT_PRI_FIRST 0
#define ACPI_EVENT_PRI_DEFAULT 10000