diff options
author | Liav A <liavalb@gmail.com> | 2020-03-03 19:28:37 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-05 19:04:04 +0100 |
commit | 1b8cd6db7bd84ff18359b1247d1a632f258e8b00 (patch) | |
tree | 04b5f57372808e797e03c18dc1c99cf1d82489d7 /Kernel | |
parent | 87582d5e63cc2460c52eb18876d51f747321e8ad (diff) | |
download | serenity-1b8cd6db7bd84ff18359b1247d1a632f258e8b00.zip |
Kernel: Call ACPI reboot method first if possible
Now we call ACPI reboot method first if possible, and if ACPI reboot is
not available, we attempt to reboot via the keyboard controller.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/ACPI/ACPIDynamicParser.cpp | 2 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIDynamicParser.h | 5 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIParser.cpp | 6 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIParser.h | 6 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIStaticParser.cpp | 21 | ||||
-rw-r--r-- | Kernel/ACPI/ACPIStaticParser.h | 6 | ||||
-rw-r--r-- | Kernel/Process.cpp | 5 |
7 files changed, 32 insertions, 19 deletions
diff --git a/Kernel/ACPI/ACPIDynamicParser.cpp b/Kernel/ACPI/ACPIDynamicParser.cpp index ab369337a0..d83ca1c5e4 100644 --- a/Kernel/ACPI/ACPIDynamicParser.cpp +++ b/Kernel/ACPI/ACPIDynamicParser.cpp @@ -82,7 +82,7 @@ namespace ACPI { // FIXME: Implement AML Interpretation ASSERT_NOT_REACHED(); } - void DynamicParser::do_acpi_shutdown() + void DynamicParser::try_acpi_shutdown() { // FIXME: Implement AML Interpretation to perform ACPI shutdown ASSERT_NOT_REACHED(); diff --git a/Kernel/ACPI/ACPIDynamicParser.h b/Kernel/ACPI/ACPIDynamicParser.h index 4ba83879bc..929648cf13 100644 --- a/Kernel/ACPI/ACPIDynamicParser.h +++ b/Kernel/ACPI/ACPIDynamicParser.h @@ -44,8 +44,9 @@ public: virtual void enable_aml_interpretation() override; virtual void enable_aml_interpretation(File& dsdt_file) override; virtual void enable_aml_interpretation(u8* physical_dsdt, u32 dsdt_payload_legnth) override; - virtual void disable_aml_interpretation() override; - virtual void do_acpi_shutdown() override; + virtual void disable_aml_interpretation() override; + virtual void try_acpi_shutdown() override; + virtual bool can_shutdown() override { return true; } protected: DynamicParser(); diff --git a/Kernel/ACPI/ACPIParser.cpp b/Kernel/ACPI/ACPIParser.cpp index cd8d8bc150..9f554d9a4f 100644 --- a/Kernel/ACPI/ACPIParser.cpp +++ b/Kernel/ACPI/ACPIParser.cpp @@ -64,16 +64,14 @@ namespace ACPI { return {}; } - void Parser::do_acpi_reboot() + void Parser::try_acpi_reboot() { klog() << "ACPI: Cannot invoke reboot!"; - ASSERT_NOT_REACHED(); } - void Parser::do_acpi_shutdown() + void Parser::try_acpi_shutdown() { klog() << "ACPI: Cannot invoke shutdown!"; - ASSERT_NOT_REACHED(); } void Parser::enable_aml_interpretation() diff --git a/Kernel/ACPI/ACPIParser.h b/Kernel/ACPI/ACPIParser.h index e3a4d17cab..2b4631e599 100644 --- a/Kernel/ACPI/ACPIParser.h +++ b/Kernel/ACPI/ACPIParser.h @@ -43,8 +43,10 @@ public: static void initialize_limited(); virtual PhysicalAddress find_table(const char* sig); - virtual void do_acpi_reboot(); - virtual void do_acpi_shutdown(); + virtual void try_acpi_reboot(); + virtual bool can_reboot() { return false; } + virtual void try_acpi_shutdown(); + virtual bool can_shutdown() { return false; } virtual void enable_aml_interpretation(); virtual void enable_aml_interpretation(File&); diff --git a/Kernel/ACPI/ACPIStaticParser.cpp b/Kernel/ACPI/ACPIStaticParser.cpp index d97f321fa4..5a3d378116 100644 --- a/Kernel/ACPI/ACPIStaticParser.cpp +++ b/Kernel/ACPI/ACPIStaticParser.cpp @@ -102,28 +102,33 @@ namespace ACPI { klog() << "ACPI: Fixed ACPI data, Revision " << sdt->revision << ", Length " << sdt->length << " bytes"; } - void StaticParser::do_acpi_reboot() + bool StaticParser::can_reboot() + { + // FIXME: Determine if we need to do MMIO/PCI/IO access to reboot, according to ACPI spec 6.2, Section 4.8.3.6 + auto region = MM.allocate_kernel_region(m_fadt.page_base(), (PAGE_SIZE * 2), "ACPI Static Parser", Region::Access::Read); + auto* fadt = (const Structures::FADT*)region->vaddr().offset(m_fadt.offset_in_page().get()).as_ptr(); + return fadt->h.revision >= 2; + } + + void StaticParser::try_acpi_reboot() { // FIXME: Determine if we need to do MMIO/PCI/IO access to reboot, according to ACPI spec 6.2, Section 4.8.3.6 #ifdef ACPI_DEBUG - dbg() << "ACPI: Rebooting, Probing FADT (P @ " << m_fadt.ptr() << ")"; + dbg() << "ACPI: Rebooting, Probing FADT (" << m_fadt << ")"; #endif + auto region = MM.allocate_kernel_region(m_fadt.page_base(), (PAGE_SIZE * 2), "ACPI Static Parser", Region::Access::Read); auto* fadt = (const Structures::FADT*)region->vaddr().offset(m_fadt.offset_in_page().get()).as_ptr(); if (fadt->h.revision >= 2) { klog() << "ACPI: Reboot, Sending value 0x" << String::format("%x", fadt->reset_value) << " to Port 0x" << String::format("%x", fadt->reset_reg.address); IO::out8(fadt->reset_reg.address, fadt->reset_value); - } else { - klog() << "ACPI: Reboot, Not supported!"; } - - ASSERT_NOT_REACHED(); /// If rebooting didn't work, halt. + klog() << "ACPI: Reboot, Not supported!"; } - void StaticParser::do_acpi_shutdown() + void StaticParser::try_acpi_shutdown() { klog() << "ACPI: Shutdown is not supported with the current configuration, Abort!"; - ASSERT_NOT_REACHED(); } size_t StaticParser::get_table_size(PhysicalAddress table_header) diff --git a/Kernel/ACPI/ACPIStaticParser.h b/Kernel/ACPI/ACPIStaticParser.h index 4cee0088de..499708f930 100644 --- a/Kernel/ACPI/ACPIStaticParser.h +++ b/Kernel/ACPI/ACPIStaticParser.h @@ -39,8 +39,10 @@ namespace ACPI { static bool is_initialized(); virtual PhysicalAddress find_table(const char* sig) override; - virtual void do_acpi_reboot() override; - virtual void do_acpi_shutdown() override; + virtual void try_acpi_reboot() override; + virtual bool can_reboot() override; + virtual bool can_shutdown() override { return false; } + virtual void try_acpi_shutdown() override; virtual bool is_operable() override { return m_operable; } protected: diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index b11089fb64..7fc8f9545f 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -31,6 +31,7 @@ #include <AK/StringBuilder.h> #include <AK/Time.h> #include <AK/Types.h> +#include <Kernel/ACPI/ACPIParser.h> #include <Kernel/Arch/i386/CPU.h> #include <Kernel/Devices/BlockDevice.h> #include <Kernel/Devices/KeyboardDevice.h> @@ -3990,6 +3991,10 @@ int Process::sys$reboot() FS::lock_all(); dbg() << "syncing mounted filesystems..."; FS::sync(); + if (ACPI::Parser::the().can_reboot()) { + dbg() << "attempting reboot via ACPI"; + ACPI::Parser::the().try_acpi_reboot(); + } dbg() << "attempting reboot via KB Controller..."; IO::out8(0x64, 0xFE); |