diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-19 00:49:28 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-19 00:49:28 -0400 |
commit | 0fa5f5f2c65d53bdc8d1a9337bc76e278dc304f2 (patch) | |
tree | e05884ff5103d8c8c16e7080eef620ca12bf2a2c /sys | |
parent | 15b2290738dc2a77ba2c9775e95a4ea7665e9aee (diff) |
kernel: acpi: Add stub power button handler
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/acpi/uacpi.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 <uacpi/sleep.h> #include <machine/cdefs.h> #include <machine/pio.h> +#include <machine/cpu.h> #if defined(__x86_64__) #include <machine/idt.h> #include <machine/ioapic.h> @@ -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; } |