2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-09-10 16:45:12 +03:00
|
|
|
* Copyright (c) 2020-2021, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01: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
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-11 11:19:33 +03:00
|
|
|
#include <AK/RefPtr.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
|
|
|
#include <AK/Types.h>
|
2021-09-10 16:45:12 +03:00
|
|
|
#include <Kernel/CommandLine.h>
|
2021-07-11 01:14:53 +02:00
|
|
|
#include <Kernel/FileSystem/SysFSComponent.h>
|
2021-09-11 10:39:47 +03:00
|
|
|
#include <Kernel/Firmware/ACPI/Definitions.h>
|
|
|
|
|
#include <Kernel/Firmware/ACPI/Initialize.h>
|
2021-09-11 11:19:33 +03:00
|
|
|
#include <Kernel/Firmware/SysFSFirmware.h>
|
2021-09-10 16:45:12 +03:00
|
|
|
#include <Kernel/Interrupts/IRQHandler.h>
|
2021-08-06 10:45:34 +02:00
|
|
|
#include <Kernel/Memory/Region.h>
|
2020-05-16 12:00:04 +02:00
|
|
|
#include <Kernel/PhysicalAddress.h>
|
|
|
|
|
#include <Kernel/VirtualAddress.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
|
|
|
|
2021-07-11 01:36:30 +02:00
|
|
|
namespace Kernel::ACPI {
|
2020-04-09 14:10:44 +02:00
|
|
|
|
2021-07-11 01:35:03 +02:00
|
|
|
class ACPISysFSDirectory : public SysFSDirectory {
|
2021-03-13 12:01:44 +02:00
|
|
|
public:
|
2021-11-08 00:51:39 +01:00
|
|
|
static ErrorOr<NonnullRefPtr<ACPISysFSDirectory>> try_create(FirmwareSysFSDirectory& firmware_directory);
|
2021-03-13 12:01:44 +02:00
|
|
|
|
|
|
|
|
private:
|
2021-09-11 11:19:33 +03:00
|
|
|
explicit ACPISysFSDirectory(FirmwareSysFSDirectory& firmware_directory);
|
2021-03-13 12:01:44 +02:00
|
|
|
};
|
|
|
|
|
|
2021-07-11 01:35:03 +02:00
|
|
|
class ACPISysFSComponent : public SysFSComponent {
|
2021-03-13 12:01:44 +02:00
|
|
|
public:
|
2021-07-11 01:35:03 +02:00
|
|
|
static NonnullRefPtr<ACPISysFSComponent> create(String name, PhysicalAddress, size_t table_size);
|
2021-03-13 12:01:44 +02:00
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
|
2021-03-13 12:01:44 +02:00
|
|
|
|
|
|
|
|
protected:
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const;
|
2021-07-11 01:35:03 +02:00
|
|
|
ACPISysFSComponent(String name, PhysicalAddress, size_t table_size);
|
2021-03-13 12:01:44 +02:00
|
|
|
|
|
|
|
|
PhysicalAddress m_paddr;
|
|
|
|
|
size_t m_length;
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-10 16:45:12 +03:00
|
|
|
class Parser final : public IRQHandler {
|
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
|
|
|
public:
|
2020-04-09 14:31:47 +02:00
|
|
|
static Parser* the();
|
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
|
|
|
|
2021-09-10 16:45:12 +03:00
|
|
|
static void must_initialize(PhysicalAddress rsdp, PhysicalAddress fadt, u8 irq_number);
|
|
|
|
|
|
2021-10-02 15:30:23 -07:00
|
|
|
virtual StringView purpose() const override { return "ACPI Parser"sv; }
|
2021-09-10 16:45:12 +03:00
|
|
|
virtual bool handle_irq(const RegisterState&) override;
|
2020-04-09 14:10:44 +02:00
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
Optional<PhysicalAddress> find_table(StringView signature);
|
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
|
|
|
|
2021-09-10 16:45:12 +03:00
|
|
|
void try_acpi_reboot();
|
|
|
|
|
bool can_reboot();
|
|
|
|
|
void try_acpi_shutdown();
|
|
|
|
|
bool can_shutdown() { return false; }
|
|
|
|
|
|
|
|
|
|
void enable_aml_parsing();
|
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
|
|
|
|
2021-03-13 12:00:13 +02:00
|
|
|
PhysicalAddress rsdp() const { return m_rsdp; }
|
|
|
|
|
PhysicalAddress main_system_description_table() const { return m_main_system_description_table; }
|
|
|
|
|
bool is_xsdt_supported() const { return m_xsdt_supported; }
|
|
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
void enumerate_static_tables(Function<void(StringView, PhysicalAddress, size_t)>);
|
2021-03-13 12:00:13 +02:00
|
|
|
|
2020-11-07 12:06:41 -07:00
|
|
|
virtual bool have_8042() const
|
|
|
|
|
{
|
|
|
|
|
return m_x86_specific_flags.keyboard_8042;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:15:02 +02:00
|
|
|
const FADTFlags::HardwareFeatures& hardware_features() const { return m_hardware_flags; }
|
|
|
|
|
const FADTFlags::x86_Specific_Flags& x86_specific_flags() const { return m_x86_specific_flags; }
|
2020-03-11 13:18:52 +02:00
|
|
|
|
2021-09-10 16:45:12 +03:00
|
|
|
~Parser() {};
|
2020-04-09 14:10:44 +02:00
|
|
|
|
|
|
|
|
private:
|
2021-09-10 16:45:12 +03:00
|
|
|
Parser(PhysicalAddress rsdp, PhysicalAddress fadt, u8 irq_number);
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
void locate_static_data();
|
|
|
|
|
void locate_main_system_description_table();
|
|
|
|
|
void initialize_main_system_description_table();
|
|
|
|
|
size_t get_table_size(PhysicalAddress);
|
|
|
|
|
u8 get_table_revision(PhysicalAddress);
|
2021-09-10 16:45:12 +03:00
|
|
|
void process_fadt_data();
|
2020-04-09 18:15:02 +02:00
|
|
|
|
|
|
|
|
bool validate_reset_register();
|
|
|
|
|
void access_generic_address(const Structures::GenericAddressStructure&, u32 value);
|
|
|
|
|
|
|
|
|
|
PhysicalAddress m_rsdp;
|
|
|
|
|
PhysicalAddress m_main_system_description_table;
|
|
|
|
|
|
|
|
|
|
Vector<PhysicalAddress> m_sdt_pointers;
|
|
|
|
|
PhysicalAddress m_fadt;
|
|
|
|
|
|
|
|
|
|
bool m_xsdt_supported { false };
|
2021-09-10 16:45:12 +03:00
|
|
|
bool m_can_process_bytecode { false };
|
2020-04-09 18:15:02 +02:00
|
|
|
FADTFlags::HardwareFeatures m_hardware_flags;
|
|
|
|
|
FADTFlags::x86_Specific_Flags m_x86_specific_flags;
|
2020-02-09 18:15:58 +02:00
|
|
|
};
|
2020-04-09 14:10:44 +02:00
|
|
|
|
2020-02-28 22:24:10 +02:00
|
|
|
}
|