From ea4f0929d094459724ff23e9fac5bd9b9d2d75bd Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 6 Aug 2021 14:03:25 +0200 Subject: [PATCH] acpi: add ACPI power off functionality Signed-off-by: Pawel Wieczorkiewicz --- Makefile | 1 - common/acpi.c | 7 +++++++ common/kernel.c | 4 ++++ include/acpi_ktf.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e438f5b5..e33f3f75 100644 --- a/Makefile +++ b/Makefile @@ -227,7 +227,6 @@ endif # HAVE_KVM QEMU_PARAMS += -m 8192 QEMU_PARAMS += -display none -vga none -vnc none QEMU_PARAMS += -serial stdio -QEMU_PARAMS += -no-reboot -no-shutdown QEMU_PARAMS += -smp cpus=2 QEMU_PARAMS_KERNEL := -append "param1 param2 param3" diff --git a/common/acpi.c b/common/acpi.c index 174c804c..f2d7ce2d 100644 --- a/common/acpi.c +++ b/common/acpi.c @@ -511,4 +511,11 @@ ACPI_STATUS init_acpi(unsigned bsp_cpu_id) { status = InitializeFullAcpi(); return status; } + +void acpi_power_off(void) { + AcpiEnterSleepStatePrep(ACPI_STATE_S5); + cli(); + AcpiEnterSleepState(ACPI_STATE_S5); + panic("Power Off"); +} #endif /* KTF_ACPICA */ diff --git a/common/kernel.c b/common/kernel.c index 84bc0c00..5816fc1a 100644 --- a/common/kernel.c +++ b/common/kernel.c @@ -22,6 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -67,5 +68,8 @@ void __naked kernel_main(void) { printk("All tasks done.\n"); +#ifdef KTF_ACPICA + acpi_power_off(); +#endif echo_loop(); } diff --git a/include/acpi_ktf.h b/include/acpi_ktf.h index 852d67b4..bcbb619d 100644 --- a/include/acpi_ktf.h +++ b/include/acpi_ktf.h @@ -289,6 +289,7 @@ extern void acpi_walk_subtables(ACPI_SUBTABLE_HEADER *entry, uint32_t length, acpi_subtable_parser_t parser, void *arg); extern ACPI_STATUS init_acpi(unsigned bsp_cpu_id); +extern void acpi_power_off(void); #endif /* KTF_ACPICA */ #endif /* KTF_ACPI_H */