From 5cc98cf104c082dc2cea7670a75bb2298047868f Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 6 Jul 2020 21:58:19 +0300 Subject: [PATCH] Add acpi event output via char device --- arch/amd64/hw/acpi.c | 17 ++++++++++++++++- include/user/acpi.h | 3 +++ install-headers.sh | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 include/user/acpi.h diff --git a/arch/amd64/hw/acpi.c b/arch/amd64/hw/acpi.c index 1db4634..25993ed 100644 --- a/arch/amd64/hw/acpi.c +++ b/arch/amd64/hw/acpi.c @@ -1,15 +1,27 @@ #include "arch/amd64/hw/acpi.h" #include "arch/amd64/hw/apic.h" #include "arch/amd64/hw/rtc.h" +#include "sys/char/ring.h" +#include "sys/char/line.h" +#include "sys/char/chr.h" #include "sys/string.h" #include "sys/debug.h" #include "sys/panic.h" +#include "user/acpi.h" +#include "sys/dev.h" #include "acpi.h" struct acpi_madt *acpi_madt = NULL; struct acpi_fadt *acpi_fadt = NULL; struct acpi_mcfg *acpi_mcfg = NULL; +static struct chrdev _acpi_event_dev = { + .dev_data = NULL, + .write = NULL, + .read = simple_line_read, + .ioctl = NULL +}; + static uint8_t checksum(const void *ptr, size_t size) { uint8_t v = 0; for (size_t i = 0; i < size; ++i) { @@ -19,7 +31,7 @@ static uint8_t checksum(const void *ptr, size_t size) { } static uint32_t acpi_power_button_handler(void *ctx) { - kinfo("Power button was pressed\n"); + ring_putc(NULL, &_acpi_event_dev.buffer, ACEV_POWER_BUTTON, 0); return 0; } @@ -161,4 +173,7 @@ void amd64_acpi_init(void) { if (ACPI_FAILURE(acpica_init())) { panic("Failed to initialize ACPICA\n"); } + + ring_init(&_acpi_event_dev.buffer, 16); + dev_add(DEV_CLASS_CHAR, 0, &_acpi_event_dev, "acpi"); } diff --git a/include/user/acpi.h b/include/user/acpi.h new file mode 100644 index 0000000..0cb4df2 --- /dev/null +++ b/include/user/acpi.h @@ -0,0 +1,3 @@ +#pragma once + +#define ACEV_POWER_BUTTON ((char) 'A') diff --git a/install-headers.sh b/install-headers.sh index b6264b2..2fc6aa2 100755 --- a/install-headers.sh +++ b/install-headers.sh @@ -26,6 +26,7 @@ KERNEL_HEADERS="include/user/fcntl.h \ include/user/video.h \ include/user/select.h \ include/user/module.h \ + include/user/acpi.h \ include/user/reboot.h" for src_file in $KERNEL_HEADERS; do