1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 17:47:43 +00:00

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.
This commit is contained in:
Liav A 2020-03-03 19:28:37 +02:00 committed by Andreas Kling
parent 87582d5e63
commit 1b8cd6db7b
7 changed files with 32 additions and 19 deletions

View file

@ -82,7 +82,7 @@ namespace ACPI {
// FIXME: Implement AML Interpretation // FIXME: Implement AML Interpretation
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
void DynamicParser::do_acpi_shutdown() void DynamicParser::try_acpi_shutdown()
{ {
// FIXME: Implement AML Interpretation to perform ACPI shutdown // FIXME: Implement AML Interpretation to perform ACPI shutdown
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -44,8 +44,9 @@ public:
virtual void enable_aml_interpretation() override; virtual void enable_aml_interpretation() override;
virtual void enable_aml_interpretation(File& dsdt_file) 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 enable_aml_interpretation(u8* physical_dsdt, u32 dsdt_payload_legnth) override;
virtual void disable_aml_interpretation() override; virtual void disable_aml_interpretation() override;
virtual void do_acpi_shutdown() override; virtual void try_acpi_shutdown() override;
virtual bool can_shutdown() override { return true; }
protected: protected:
DynamicParser(); DynamicParser();

View file

@ -64,16 +64,14 @@ namespace ACPI {
return {}; return {};
} }
void Parser::do_acpi_reboot() void Parser::try_acpi_reboot()
{ {
klog() << "ACPI: Cannot invoke reboot!"; klog() << "ACPI: Cannot invoke reboot!";
ASSERT_NOT_REACHED();
} }
void Parser::do_acpi_shutdown() void Parser::try_acpi_shutdown()
{ {
klog() << "ACPI: Cannot invoke shutdown!"; klog() << "ACPI: Cannot invoke shutdown!";
ASSERT_NOT_REACHED();
} }
void Parser::enable_aml_interpretation() void Parser::enable_aml_interpretation()

View file

@ -43,8 +43,10 @@ public:
static void initialize_limited(); static void initialize_limited();
virtual PhysicalAddress find_table(const char* sig); virtual PhysicalAddress find_table(const char* sig);
virtual void do_acpi_reboot(); virtual void try_acpi_reboot();
virtual void do_acpi_shutdown(); 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();
virtual void enable_aml_interpretation(File&); virtual void enable_aml_interpretation(File&);

View file

@ -102,28 +102,33 @@ namespace ACPI {
klog() << "ACPI: Fixed ACPI data, Revision " << sdt->revision << ", Length " << sdt->length << " bytes"; 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 // 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 #ifdef ACPI_DEBUG
dbg() << "ACPI: Rebooting, Probing FADT (P @ " << m_fadt.ptr() << ")"; dbg() << "ACPI: Rebooting, Probing FADT (" << m_fadt << ")";
#endif #endif
auto region = MM.allocate_kernel_region(m_fadt.page_base(), (PAGE_SIZE * 2), "ACPI Static Parser", Region::Access::Read); 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(); auto* fadt = (const Structures::FADT*)region->vaddr().offset(m_fadt.offset_in_page().get()).as_ptr();
if (fadt->h.revision >= 2) { 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); 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); IO::out8(fadt->reset_reg.address, fadt->reset_value);
} else {
klog() << "ACPI: Reboot, Not supported!";
} }
klog() << "ACPI: Reboot, Not supported!";
ASSERT_NOT_REACHED(); /// If rebooting didn't work, halt.
} }
void StaticParser::do_acpi_shutdown() void StaticParser::try_acpi_shutdown()
{ {
klog() << "ACPI: Shutdown is not supported with the current configuration, Abort!"; klog() << "ACPI: Shutdown is not supported with the current configuration, Abort!";
ASSERT_NOT_REACHED();
} }
size_t StaticParser::get_table_size(PhysicalAddress table_header) size_t StaticParser::get_table_size(PhysicalAddress table_header)

View file

@ -39,8 +39,10 @@ namespace ACPI {
static bool is_initialized(); static bool is_initialized();
virtual PhysicalAddress find_table(const char* sig) override; virtual PhysicalAddress find_table(const char* sig) override;
virtual void do_acpi_reboot() override; virtual void try_acpi_reboot() override;
virtual void do_acpi_shutdown() 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; } virtual bool is_operable() override { return m_operable; }
protected: protected:

View file

@ -31,6 +31,7 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/ACPI/ACPIParser.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Devices/BlockDevice.h> #include <Kernel/Devices/BlockDevice.h>
#include <Kernel/Devices/KeyboardDevice.h> #include <Kernel/Devices/KeyboardDevice.h>
@ -3990,6 +3991,10 @@ int Process::sys$reboot()
FS::lock_all(); FS::lock_all();
dbg() << "syncing mounted filesystems..."; dbg() << "syncing mounted filesystems...";
FS::sync(); 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..."; dbg() << "attempting reboot via KB Controller...";
IO::out8(0x64, 0xFE); IO::out8(0x64, 0xFE);