2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-03-06 16:55:17 +02:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-04-09 18:15:02 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-23 13:45:10 +01:00
|
|
|
#include <AK/StringView.h>
|
2020-04-09 18:17:27 +02:00
|
|
|
#include <Kernel/ACPI/Parser.h>
|
2020-05-22 12:55:23 +02:00
|
|
|
#include <Kernel/Arch/PC/BIOS.h>
|
2021-01-25 16:07:10 +01:00
|
|
|
#include <Kernel/Debug.h>
|
2020-05-22 12:55:23 +02:00
|
|
|
#include <Kernel/IO.h>
|
2020-04-09 18:15:02 +02:00
|
|
|
#include <Kernel/PCI/Access.h>
|
2020-05-22 12:55:23 +02:00
|
|
|
#include <Kernel/StdLib.h>
|
2020-04-09 18:15:02 +02:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
|
#include <Kernel/VM/TypedMapping.h>
|
Kernel: Introduce the ACPI subsystem
ACPI subsystem includes 3 types of parsers that are created during
runtime, each one capable of parsing ACPI tables at different level.
ACPIParser is the most basic parser which is essentialy a parser that
can't parse anything useful, due to a user request to disable ACPI
support in a kernel boot parameter.
ACPIStaticParser is a derived class from ACPIParser, which is able to
parse only static data (e.g. FADT, HPET, MCFG and other tables), thus
making it not able to parse AML (ACPI Machine Language) nor to support
handling of hardware events and power management. This type of parser
can be created with a kernel boot parameter.
ACPIDynamicParser is a derived class from ACPIStaticParser, which
includes all the capabilities of the latter, but *should* implement an
AML interpretation, (by building the ACPI AML namespace) and handling
power & hardware events. Currently the methods to support AML
interpretation are not implemented.
This type of parser is created automatically during runtime if the user
didn't specify a boot parameter related to ACPI initialization.
Also, adding strncmp function definition in StdLib.h, to be able to use
it in ACPIStaticParser class.
2019-12-31 13:01:09 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
2020-02-28 22:24:10 +02:00
|
|
|
namespace ACPI {
|
2020-04-09 14:10:44 +02:00
|
|
|
|
2020-03-22 13:12:45 +13:00
|
|
|
static Parser* s_acpi_parser;
|
2020-02-16 01:27:42 +01:00
|
|
|
|
2020-04-09 14:31:47 +02:00
|
|
|
Parser* Parser::the()
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-04-09 14:31:47 +02:00
|
|
|
return s_acpi_parser;
|
2020-03-22 13:12:45 +13:00
|
|
|
}
|
Kernel: Introduce the ACPI subsystem
ACPI subsystem includes 3 types of parsers that are created during
runtime, each one capable of parsing ACPI tables at different level.
ACPIParser is the most basic parser which is essentialy a parser that
can't parse anything useful, due to a user request to disable ACPI
support in a kernel boot parameter.
ACPIStaticParser is a derived class from ACPIParser, which is able to
parse only static data (e.g. FADT, HPET, MCFG and other tables), thus
making it not able to parse AML (ACPI Machine Language) nor to support
handling of hardware events and power management. This type of parser
can be created with a kernel boot parameter.
ACPIDynamicParser is a derived class from ACPIStaticParser, which
includes all the capabilities of the latter, but *should* implement an
AML interpretation, (by building the ACPI AML namespace) and handling
power & hardware events. Currently the methods to support AML
interpretation are not implemented.
This type of parser is created automatically during runtime if the user
didn't specify a boot parameter related to ACPI initialization.
Also, adding strncmp function definition in StdLib.h, to be able to use
it in ACPIStaticParser class.
2019-12-31 13:01:09 +02:00
|
|
|
|
2020-04-09 14:10:44 +02:00
|
|
|
void Parser::set_the(Parser& parser)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-04-09 14:10:44 +02:00
|
|
|
ASSERT(!s_acpi_parser);
|
|
|
|
|
s_acpi_parser = &parser;
|
2020-03-22 13:12:45 +13:00
|
|
|
}
|
Kernel: Introduce the ACPI subsystem
ACPI subsystem includes 3 types of parsers that are created during
runtime, each one capable of parsing ACPI tables at different level.
ACPIParser is the most basic parser which is essentialy a parser that
can't parse anything useful, due to a user request to disable ACPI
support in a kernel boot parameter.
ACPIStaticParser is a derived class from ACPIParser, which is able to
parse only static data (e.g. FADT, HPET, MCFG and other tables), thus
making it not able to parse AML (ACPI Machine Language) nor to support
handling of hardware events and power management. This type of parser
can be created with a kernel boot parameter.
ACPIDynamicParser is a derived class from ACPIStaticParser, which
includes all the capabilities of the latter, but *should* implement an
AML interpretation, (by building the ACPI AML namespace) and handling
power & hardware events. Currently the methods to support AML
interpretation are not implemented.
This type of parser is created automatically during runtime if the user
didn't specify a boot parameter related to ACPI initialization.
Also, adding strncmp function definition in StdLib.h, to be able to use
it in ACPIStaticParser class.
2019-12-31 13:01:09 +02:00
|
|
|
|
2020-04-09 18:15:02 +02:00
|
|
|
static bool match_table_signature(PhysicalAddress table_header, const StringView& signature);
|
|
|
|
|
static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt, const StringView& signature);
|
|
|
|
|
static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt, const StringView& signature);
|
|
|
|
|
static bool validate_table(const Structures::SDTHeader&, size_t length);
|
|
|
|
|
|
|
|
|
|
void Parser::locate_static_data()
|
|
|
|
|
{
|
|
|
|
|
locate_main_system_description_table();
|
|
|
|
|
initialize_main_system_description_table();
|
|
|
|
|
init_fadt();
|
|
|
|
|
init_facs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhysicalAddress Parser::find_table(const StringView& signature)
|
|
|
|
|
{
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Calling Find Table method!");
|
2020-04-09 18:15:02 +02:00
|
|
|
for (auto p_sdt : m_sdt_pointers) {
|
|
|
|
|
auto sdt = map_typed<Structures::SDTHeader>(p_sdt);
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Examining Table @ {}", p_sdt);
|
2020-04-09 18:15:02 +02:00
|
|
|
if (!strncmp(sdt->sig, signature.characters_without_null_termination(), 4)) {
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Found Table @ {}", p_sdt);
|
2020-04-09 18:15:02 +02:00
|
|
|
return p_sdt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::init_facs()
|
|
|
|
|
{
|
|
|
|
|
m_facs = find_table("FACS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::init_fadt()
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-04-09 18:15:02 +02:00
|
|
|
klog() << "ACPI: Initializing Fixed ACPI data";
|
|
|
|
|
klog() << "ACPI: Searching for the Fixed ACPI Data Table";
|
|
|
|
|
|
|
|
|
|
m_fadt = find_table("FACP");
|
|
|
|
|
ASSERT(!m_fadt.is_null());
|
|
|
|
|
|
|
|
|
|
auto sdt = map_typed<Structures::FADT>(m_fadt);
|
|
|
|
|
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: FADT @ V{}, {}", &sdt, m_fadt);
|
2021-01-13 21:16:18 +01:00
|
|
|
|
2020-04-09 18:15:02 +02:00
|
|
|
klog() << "ACPI: Fixed ACPI data, Revision " << sdt->h.revision << ", Length " << sdt->h.length << " bytes";
|
|
|
|
|
klog() << "ACPI: DSDT " << PhysicalAddress(sdt->dsdt_ptr);
|
|
|
|
|
m_x86_specific_flags.cmos_rtc_not_present = (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::CMOS_RTC_Not_Present);
|
2020-12-17 21:37:37 +02:00
|
|
|
|
|
|
|
|
// FIXME: QEMU doesn't report that we have an i8042 controller in these flags, even if it should (when FADT revision is 3),
|
|
|
|
|
// Later on, we need to make sure that we enumerate the ACPI namespace (AML encoded), instead of just using this value.
|
|
|
|
|
m_x86_specific_flags.keyboard_8042 = (sdt->h.revision <= 3) || (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::PS2_8042);
|
|
|
|
|
|
2020-04-09 18:15:02 +02:00
|
|
|
m_x86_specific_flags.legacy_devices = (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::Legacy_Devices);
|
|
|
|
|
m_x86_specific_flags.msi_not_supported = (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::MSI_Not_Supported);
|
|
|
|
|
m_x86_specific_flags.vga_not_present = (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::VGA_Not_Present);
|
|
|
|
|
|
|
|
|
|
m_hardware_flags.cpu_software_sleep = (sdt->flags & (u32)FADTFlags::FeatureFlags::CPU_SW_SLP);
|
|
|
|
|
m_hardware_flags.docking_capability = (sdt->flags & (u32)FADTFlags::FeatureFlags::DCK_CAP);
|
|
|
|
|
m_hardware_flags.fix_rtc = (sdt->flags & (u32)FADTFlags::FeatureFlags::FIX_RTC);
|
|
|
|
|
m_hardware_flags.force_apic_cluster_model = (sdt->flags & (u32)FADTFlags::FeatureFlags::FORCE_APIC_CLUSTER_MODEL);
|
|
|
|
|
m_hardware_flags.force_apic_physical_destination_mode = (sdt->flags & (u32)FADTFlags::FeatureFlags::FORCE_APIC_PHYSICAL_DESTINATION_MODE);
|
|
|
|
|
m_hardware_flags.hardware_reduced_acpi = (sdt->flags & (u32)FADTFlags::FeatureFlags::HW_REDUCED_ACPI);
|
|
|
|
|
m_hardware_flags.headless = (sdt->flags & (u32)FADTFlags::FeatureFlags::HEADLESS);
|
|
|
|
|
m_hardware_flags.low_power_s0_idle_capable = (sdt->flags & (u32)FADTFlags::FeatureFlags::LOW_POWER_S0_IDLE_CAPABLE);
|
|
|
|
|
m_hardware_flags.multiprocessor_c2 = (sdt->flags & (u32)FADTFlags::FeatureFlags::P_LVL2_UP);
|
|
|
|
|
m_hardware_flags.pci_express_wake = (sdt->flags & (u32)FADTFlags::FeatureFlags::PCI_EXP_WAK);
|
|
|
|
|
m_hardware_flags.power_button = (sdt->flags & (u32)FADTFlags::FeatureFlags::PWR_BUTTON);
|
|
|
|
|
m_hardware_flags.processor_c1 = (sdt->flags & (u32)FADTFlags::FeatureFlags::PROC_C1);
|
|
|
|
|
m_hardware_flags.remote_power_on_capable = (sdt->flags & (u32)FADTFlags::FeatureFlags::REMOTE_POWER_ON_CAPABLE);
|
|
|
|
|
m_hardware_flags.reset_register_supported = (sdt->flags & (u32)FADTFlags::FeatureFlags::RESET_REG_SUPPORTED);
|
|
|
|
|
m_hardware_flags.rtc_s4 = (sdt->flags & (u32)FADTFlags::FeatureFlags::RTC_s4);
|
|
|
|
|
m_hardware_flags.s4_rtc_status_valid = (sdt->flags & (u32)FADTFlags::FeatureFlags::S4_RTC_STS_VALID);
|
|
|
|
|
m_hardware_flags.sealed_case = (sdt->flags & (u32)FADTFlags::FeatureFlags::SEALED_CASE);
|
|
|
|
|
m_hardware_flags.sleep_button = (sdt->flags & (u32)FADTFlags::FeatureFlags::SLP_BUTTON);
|
|
|
|
|
m_hardware_flags.timer_value_extension = (sdt->flags & (u32)FADTFlags::FeatureFlags::TMR_VAL_EXT);
|
|
|
|
|
m_hardware_flags.use_platform_clock = (sdt->flags & (u32)FADTFlags::FeatureFlags::USE_PLATFORM_CLOCK);
|
|
|
|
|
m_hardware_flags.wbinvd = (sdt->flags & (u32)FADTFlags::FeatureFlags::WBINVD);
|
|
|
|
|
m_hardware_flags.wbinvd_flush = (sdt->flags & (u32)FADTFlags::FeatureFlags::WBINVD_FLUSH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Parser::can_reboot()
|
|
|
|
|
{
|
|
|
|
|
auto fadt = map_typed<Structures::FADT>(m_fadt);
|
|
|
|
|
if (fadt->h.revision < 2)
|
|
|
|
|
return false;
|
|
|
|
|
return m_hardware_flags.reset_register_supported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::access_generic_address(const Structures::GenericAddressStructure& structure, u32 value)
|
|
|
|
|
{
|
|
|
|
|
switch ((GenericAddressStructure::AddressSpace)structure.address_space) {
|
|
|
|
|
case GenericAddressStructure::AddressSpace::SystemIO: {
|
|
|
|
|
IOAddress address(structure.address);
|
2021-01-25 12:52:31 +01:00
|
|
|
dbgln("ACPI: Sending value {:x} to {}", value, address);
|
2020-04-09 18:15:02 +02:00
|
|
|
switch (structure.access_size) {
|
|
|
|
|
case (u8)GenericAddressStructure::AccessSize::QWord: {
|
2021-01-09 00:42:44 +01:00
|
|
|
dbgln("Trying to send QWord to IO port");
|
2020-04-09 18:15:02 +02:00
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case (u8)GenericAddressStructure::AccessSize::Undefined: {
|
2021-01-09 00:42:44 +01:00
|
|
|
dbgln("ACPI Warning: Unknown access size {}", structure.access_size);
|
2020-04-09 18:15:02 +02:00
|
|
|
ASSERT(structure.bit_width != (u8)GenericAddressStructure::BitWidth::QWord);
|
|
|
|
|
ASSERT(structure.bit_width != (u8)GenericAddressStructure::BitWidth::Undefined);
|
2021-01-10 14:24:59 +01:00
|
|
|
dbgln("ACPI: Bit Width - {} bits", structure.bit_width);
|
2020-04-09 18:15:02 +02:00
|
|
|
address.out(value, structure.bit_width);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
address.out(value, (8 << (structure.access_size - 1)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case GenericAddressStructure::AddressSpace::SystemMemory: {
|
2021-01-09 00:42:44 +01:00
|
|
|
dbgln("ACPI: Sending value {:x} to {}", value, PhysicalAddress(structure.address));
|
2020-04-09 18:15:02 +02:00
|
|
|
switch ((GenericAddressStructure::AccessSize)structure.access_size) {
|
|
|
|
|
case GenericAddressStructure::AccessSize::Byte:
|
|
|
|
|
*map_typed<u8>(PhysicalAddress(structure.address)) = value;
|
|
|
|
|
break;
|
|
|
|
|
case GenericAddressStructure::AccessSize::Word:
|
|
|
|
|
*map_typed<u16>(PhysicalAddress(structure.address)) = value;
|
|
|
|
|
break;
|
|
|
|
|
case GenericAddressStructure::AccessSize::DWord:
|
|
|
|
|
*map_typed<u32>(PhysicalAddress(structure.address)) = value;
|
|
|
|
|
break;
|
|
|
|
|
case GenericAddressStructure::AccessSize::QWord: {
|
|
|
|
|
*map_typed<u64>(PhysicalAddress(structure.address)) = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case GenericAddressStructure::AddressSpace::PCIConfigurationSpace: {
|
|
|
|
|
// According to the ACPI specification 6.2, page 168, PCI addresses must be confined to devices on Segment group 0, bus 0.
|
|
|
|
|
auto pci_address = PCI::Address(0, 0, ((structure.address >> 24) & 0xFF), ((structure.address >> 16) & 0xFF));
|
2021-01-09 00:42:44 +01:00
|
|
|
dbgln("ACPI: Sending value {:x} to {}", value, pci_address);
|
2020-04-09 18:15:02 +02:00
|
|
|
u32 offset_in_pci_address = structure.address & 0xFFFF;
|
|
|
|
|
if (structure.access_size == (u8)GenericAddressStructure::AccessSize::QWord) {
|
2021-01-09 00:42:44 +01:00
|
|
|
dbgln("Trying to send QWord to PCI configuration space");
|
2020-04-09 18:15:02 +02:00
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
ASSERT(structure.access_size != (u8)GenericAddressStructure::AccessSize::Undefined);
|
|
|
|
|
PCI::raw_access(pci_address, offset_in_pci_address, (1 << (structure.access_size - 1)), value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-03-22 13:12:45 +13:00
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
bool Parser::validate_reset_register()
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
2020-04-09 18:15:02 +02:00
|
|
|
// According to the ACPI spec 6.2, page 152, The reset register can only be located in I/O bus, PCI bus or memory-mapped.
|
|
|
|
|
auto fadt = map_typed<Structures::FADT>(m_fadt);
|
|
|
|
|
return (fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::PCIConfigurationSpace || fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::SystemMemory || fadt->reset_reg.address_space == (u8)GenericAddressStructure::AddressSpace::SystemIO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::try_acpi_reboot()
|
|
|
|
|
{
|
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
if (!can_reboot()) {
|
|
|
|
|
klog() << "ACPI: Reboot, Not supported!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Rebooting, Probing FADT ({})", m_fadt);
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
auto fadt = map_typed<Structures::FADT>(m_fadt);
|
|
|
|
|
ASSERT(validate_reset_register());
|
|
|
|
|
access_generic_address(fadt->reset_reg, fadt->reset_value);
|
2020-07-06 07:27:22 -06:00
|
|
|
Processor::halt();
|
2020-04-09 18:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::try_acpi_shutdown()
|
|
|
|
|
{
|
|
|
|
|
klog() << "ACPI: Shutdown is not supported with the current configuration, Abort!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Parser::get_table_size(PhysicalAddress table_header)
|
|
|
|
|
{
|
|
|
|
|
InterruptDisabler disabler;
|
2021-01-23 23:29:11 +01:00
|
|
|
#if ACPI_DEBUG
|
2021-01-09 18:51:44 +01:00
|
|
|
dbgln("ACPI: Checking SDT Length");
|
2020-04-09 18:15:02 +02:00
|
|
|
#endif
|
|
|
|
|
return map_typed<Structures::SDTHeader>(table_header)->length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u8 Parser::get_table_revision(PhysicalAddress table_header)
|
|
|
|
|
{
|
|
|
|
|
InterruptDisabler disabler;
|
2021-01-23 23:29:11 +01:00
|
|
|
#if ACPI_DEBUG
|
2021-01-09 18:51:44 +01:00
|
|
|
dbgln("ACPI: Checking SDT Revision");
|
2020-04-09 18:15:02 +02:00
|
|
|
#endif
|
|
|
|
|
return map_typed<Structures::SDTHeader>(table_header)->revision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::initialize_main_system_description_table()
|
|
|
|
|
{
|
2021-01-23 23:29:11 +01:00
|
|
|
#if ACPI_DEBUG
|
2021-01-09 18:51:44 +01:00
|
|
|
dbgln("ACPI: Checking Main SDT Length to choose the correct mapping size");
|
2020-04-09 18:15:02 +02:00
|
|
|
#endif
|
|
|
|
|
ASSERT(!m_main_system_description_table.is_null());
|
|
|
|
|
auto length = get_table_size(m_main_system_description_table);
|
|
|
|
|
auto revision = get_table_revision(m_main_system_description_table);
|
|
|
|
|
|
|
|
|
|
auto sdt = map_typed<Structures::SDTHeader>(m_main_system_description_table, length);
|
|
|
|
|
|
|
|
|
|
klog() << "ACPI: Main Description Table valid? " << validate_table(*sdt, length);
|
|
|
|
|
|
|
|
|
|
if (m_xsdt_supported) {
|
|
|
|
|
auto& xsdt = (const Structures::XSDT&)*sdt;
|
|
|
|
|
klog() << "ACPI: Using XSDT, Enumerating tables @ " << m_main_system_description_table;
|
|
|
|
|
klog() << "ACPI: XSDT Revision " << revision << ", Total length - " << length;
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: XSDT pointer @ V{}", &xsdt);
|
2020-04-09 18:15:02 +02:00
|
|
|
for (u32 i = 0; i < ((length - sizeof(Structures::SDTHeader)) / sizeof(u64)); i++) {
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Found new table [{0}], @ V{1:p} - P{1:p}", i, &xsdt.table_ptrs[i]);
|
2020-04-09 18:15:02 +02:00
|
|
|
m_sdt_pointers.append(PhysicalAddress(xsdt.table_ptrs[i]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
auto& rsdt = (const Structures::RSDT&)*sdt;
|
|
|
|
|
klog() << "ACPI: Using RSDT, Enumerating tables @ " << m_main_system_description_table;
|
|
|
|
|
klog() << "ACPI: RSDT Revision " << revision << ", Total length - " << length;
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: RSDT pointer @ V{}", &rsdt);
|
2020-04-09 18:15:02 +02:00
|
|
|
for (u32 i = 0; i < ((length - sizeof(Structures::SDTHeader)) / sizeof(u32)); i++) {
|
2021-01-23 23:59:27 +01:00
|
|
|
dbgln<ACPI_DEBUG>("ACPI: Found new table [{0}], @ V{1:p} - P{1:p}", i, &rsdt.table_ptrs[i]);
|
2020-04-09 18:15:02 +02:00
|
|
|
m_sdt_pointers.append(PhysicalAddress(rsdt.table_ptrs[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::locate_main_system_description_table()
|
|
|
|
|
{
|
|
|
|
|
auto rsdp = map_typed<Structures::RSDPDescriptor20>(m_rsdp);
|
|
|
|
|
if (rsdp->base.revision == 0) {
|
|
|
|
|
m_xsdt_supported = false;
|
|
|
|
|
} else if (rsdp->base.revision >= 2) {
|
|
|
|
|
if (rsdp->xsdt_ptr != (u64) nullptr) {
|
|
|
|
|
m_xsdt_supported = true;
|
|
|
|
|
} else {
|
|
|
|
|
m_xsdt_supported = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!m_xsdt_supported) {
|
|
|
|
|
m_main_system_description_table = PhysicalAddress(rsdp->base.rsdt_ptr);
|
|
|
|
|
} else {
|
|
|
|
|
m_main_system_description_table = PhysicalAddress(rsdp->xsdt_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Parser::Parser(PhysicalAddress rsdp)
|
|
|
|
|
: m_rsdp(rsdp)
|
|
|
|
|
{
|
|
|
|
|
klog() << "ACPI: Using RSDP @ " << rsdp;
|
|
|
|
|
locate_static_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool validate_table(const Structures::SDTHeader& v_header, size_t length)
|
|
|
|
|
{
|
|
|
|
|
u8 checksum = 0;
|
|
|
|
|
auto* sdt = (const u8*)&v_header;
|
|
|
|
|
for (size_t i = 0; i < length; i++)
|
|
|
|
|
checksum += sdt[i];
|
|
|
|
|
if (checksum == 0)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 13:34:53 +02:00
|
|
|
Optional<PhysicalAddress> StaticParsing::find_rsdp()
|
2020-04-09 18:15:02 +02:00
|
|
|
{
|
2020-05-22 13:34:53 +02:00
|
|
|
StringView signature("RSD PTR ");
|
|
|
|
|
auto rsdp = map_ebda().find_chunk_starting_with(signature, 16);
|
|
|
|
|
if (rsdp.has_value())
|
2020-04-09 18:15:02 +02:00
|
|
|
return rsdp;
|
2020-05-22 13:34:53 +02:00
|
|
|
return map_bios().find_chunk_starting_with(signature, 16);
|
2020-04-09 18:15:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
|
|
|
|
|
ASSERT(signature.length() == 4);
|
|
|
|
|
|
|
|
|
|
auto rsdp = map_typed<Structures::RSDPDescriptor20>(rsdp_address);
|
|
|
|
|
|
|
|
|
|
if (rsdp->base.revision == 0)
|
|
|
|
|
return search_table_in_rsdt(PhysicalAddress(rsdp->base.rsdt_ptr), signature);
|
|
|
|
|
|
|
|
|
|
if (rsdp->base.revision >= 2) {
|
|
|
|
|
if (rsdp->xsdt_ptr)
|
|
|
|
|
return search_table_in_xsdt(PhysicalAddress(rsdp->xsdt_ptr), signature);
|
|
|
|
|
return search_table_in_rsdt(PhysicalAddress(rsdp->base.rsdt_ptr), signature);
|
|
|
|
|
}
|
2020-03-22 13:12:45 +13:00
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
|
|
|
|
|
ASSERT(signature.length() == 4);
|
|
|
|
|
|
|
|
|
|
auto xsdt = map_typed<Structures::XSDT>(xsdt_address);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ((xsdt->h.length - sizeof(Structures::SDTHeader)) / sizeof(u64)); ++i) {
|
|
|
|
|
if (match_table_signature(PhysicalAddress((FlatPtr)xsdt->table_ptrs[i]), signature))
|
|
|
|
|
return PhysicalAddress((FlatPtr)xsdt->table_ptrs[i]);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool match_table_signature(PhysicalAddress table_header, const StringView& signature)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
|
|
|
|
|
ASSERT(signature.length() == 4);
|
|
|
|
|
|
|
|
|
|
auto table = map_typed<Structures::RSDT>(table_header);
|
|
|
|
|
return !strncmp(table->h.sig, signature.characters_without_null_termination(), 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables.
|
|
|
|
|
ASSERT(signature.length() == 4);
|
|
|
|
|
|
|
|
|
|
auto rsdt = map_typed<Structures::RSDT>(rsdt_address);
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < ((rsdt->h.length - sizeof(Structures::SDTHeader)) / sizeof(u32)); i++) {
|
|
|
|
|
if (match_table_signature(PhysicalAddress((FlatPtr)rsdt->table_ptrs[i]), signature))
|
|
|
|
|
return PhysicalAddress((FlatPtr)rsdt->table_ptrs[i]);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Parser::enable_aml_interpretation()
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
void Parser::enable_aml_interpretation(File&)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
void Parser::enable_aml_interpretation(u8*, u32)
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
void Parser::disable_aml_interpretation()
|
2020-03-22 13:12:45 +13:00
|
|
|
{
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
2020-04-09 18:15:02 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|
|
|
|
|
}
|