From 0fa5f5f2c65d53bdc8d1a9337bc76e278dc304f2 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 19 May 2025 00:49:28 -0400 Subject: kernel: acpi: Add stub power button handler Signed-off-by: Ian Moffett --- sys/dev/acpi/uacpi.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sys/dev') diff --git a/sys/dev/acpi/uacpi.c b/sys/dev/acpi/uacpi.c index 9e5ae6b..7dbcb35 100644 --- a/sys/dev/acpi/uacpi.c +++ b/sys/dev/acpi/uacpi.c @@ -40,6 +40,7 @@ #include #include #include +#include #if defined(__x86_64__) #include #include @@ -57,6 +58,19 @@ typedef struct { uacpi_size length; } io_range_t; +/* + * TODO: Schedule a system shutdown + */ +static uacpi_interrupt_ret +power_button_handler(uacpi_handle ctx) +{ + md_intoff(); + kprintf("power button pressed\n"); + kprintf("halting machine...\n"); + cpu_halt_all(); + return UACPI_INTERRUPT_HANDLED; +} + void * uacpi_kernel_alloc(uacpi_size size) { @@ -541,5 +555,17 @@ uacpi_init(void) return -1; } + ret = uacpi_install_fixed_event_handler( + UACPI_FIXED_EVENT_POWER_BUTTON, + power_button_handler, UACPI_NULL + ); + + if (uacpi_unlikely_error(ret)) { + kprintf("failed to install power button event: %s\n", + uacpi_status_to_string(ret) + ); + return -1; + } + return 0; } -- cgit v1.2.3