bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] acpi_init: Add enter_sleep method based on ACPI server


From: Damien Zammit
Subject: [PATCH 4/5] acpi_init: Add enter_sleep method based on ACPI server
Date: Thu, 1 Apr 2021 00:23:29 +1100

---
 libacpica/acpi_init.c    | 43 ++++++++++++++++++++++++++++++++++++++++
 shutdown/acpi_shutdown.h |  1 +
 2 files changed, 44 insertions(+)

diff --git a/libacpica/acpi_init.c b/libacpica/acpi_init.c
index 754da4be..405ad4e9 100644
--- a/libacpica/acpi_init.c
+++ b/libacpica/acpi_init.c
@@ -13,6 +13,49 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <shutdown/acpi_shutdown.h>
+
+acpi_status
+acpi_os_enter_sleep(u8 sleep_state, u32 pm1a, u32 pm1b)
+{
+       uint16_t pm1a_ctl, pm1b_ctl;
+       uint8_t regbuf[2];
+       FILE *facp;
+
+       /* Open the ACPI FADT table */
+       facp = fopen(SERVERS_ACPI_FADT, "r");
+       if (!facp)
+               return AE_NO_ACPI_TABLES;
+
+       /* Grab PM1a Control I/O port */
+       fseek(facp, PM1A_CTL_OFFSET, SEEK_SET);
+       fread(regbuf, 2, 1, facp);
+       pm1a_ctl = (uint16_t)regbuf[0] |
+                  ((uint16_t)regbuf[1] << 8);
+
+       /* Grab PM1a Control I/O port */
+       fseek(facp, PM1B_CTL_OFFSET, SEEK_SET);
+       fread(regbuf, 2, 1, facp);
+       pm1b_ctl = (uint16_t)regbuf[0] |
+                  ((uint16_t)regbuf[1] << 8);
+
+       /* Close the ACPI FADT table */
+       fclose(facp);
+
+       if (ioperm(pm1a_ctl, 2, 1)) {
+               fprintf(stderr, "EPERM on ioperm(pm1a_ctl)\n");
+               return AE_IO_ERROR;
+       }
+
+       if (ioperm(pm1b_ctl, 2, 1)) {
+               fprintf(stderr, "EPERM on ioperm(pm1b_ctl)\n");
+               return AE_IO_ERROR;
+       }
+
+       outw(pm1a, pm1a_ctl);
+       outw(pm1b, pm1b_ctl);
+       return AE_OK;
+}
 
 void
 acpi_ds_dump_method_stack(acpi_status status, ...)
diff --git a/shutdown/acpi_shutdown.h b/shutdown/acpi_shutdown.h
index 50b7f1f6..897fbad3 100644
--- a/shutdown/acpi_shutdown.h
+++ b/shutdown/acpi_shutdown.h
@@ -12,6 +12,7 @@
 #define SMI_CMD_OFFSET 12
 #define SMI_EN_OFFSET  16
 #define PM1A_CTL_OFFSET        28
+#define PM1B_CTL_OFFSET        32
 
 void disappear_via_acpi(void);
 
-- 
2.30.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]