2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2020-03-06 14:55:17 +00:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00: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 11:01:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
#include <Kernel/ACPI/Definitions.h>
|
2020-04-09 12:31:47 +00:00
|
|
|
#include <Kernel/ACPI/Initialize.h>
|
2021-07-10 23:14:53 +00:00
|
|
|
#include <Kernel/FileSystem/SysFSComponent.h>
|
2021-08-06 08:45:34 +00:00
|
|
|
#include <Kernel/Memory/Region.h>
|
2020-05-16 10:00:04 +00: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 11:01:09 +00:00
|
|
|
|
2021-07-10 23:36:30 +00:00
|
|
|
namespace Kernel::ACPI {
|
2020-04-09 12:10:44 +00:00
|
|
|
|
2021-07-10 23:35:03 +00:00
|
|
|
class ACPISysFSDirectory : public SysFSDirectory {
|
2021-03-13 10:01:44 +00:00
|
|
|
public:
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
private:
|
2021-07-10 23:35:03 +00:00
|
|
|
ACPISysFSDirectory();
|
2021-03-13 10:01:44 +00:00
|
|
|
};
|
|
|
|
|
2021-07-10 23:35:03 +00:00
|
|
|
class ACPISysFSComponent : public SysFSComponent {
|
2021-03-13 10:01:44 +00:00
|
|
|
public:
|
2021-07-10 23:35:03 +00:00
|
|
|
static NonnullRefPtr<ACPISysFSComponent> create(String name, PhysicalAddress, size_t table_size);
|
2021-03-13 10:01:44 +00:00
|
|
|
|
|
|
|
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
OwnPtr<KBuffer> try_to_generate_buffer() const;
|
2021-07-10 23:35:03 +00:00
|
|
|
ACPISysFSComponent(String name, PhysicalAddress, size_t table_size);
|
2021-03-13 10:01:44 +00:00
|
|
|
|
|
|
|
PhysicalAddress m_paddr;
|
|
|
|
size_t m_length;
|
|
|
|
};
|
|
|
|
|
2020-02-28 20:24:10 +00:00
|
|
|
class Parser {
|
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 11:01:09 +00:00
|
|
|
public:
|
2020-04-09 12:31:47 +00: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 11:01:09 +00:00
|
|
|
|
2020-04-09 12:10:44 +00:00
|
|
|
template<typename ParserType>
|
2020-04-09 12:31:47 +00:00
|
|
|
static void initialize(PhysicalAddress rsdp)
|
2020-04-09 12:10:44 +00:00
|
|
|
{
|
2020-04-09 12:31:47 +00:00
|
|
|
set_the(*new ParserType(rsdp));
|
2020-04-09 12:10:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:15:02 +00:00
|
|
|
virtual PhysicalAddress find_table(const 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 11:01:09 +00:00
|
|
|
|
2020-04-09 16:15:02 +00:00
|
|
|
virtual void try_acpi_reboot();
|
|
|
|
virtual bool can_reboot();
|
|
|
|
virtual void try_acpi_shutdown();
|
|
|
|
virtual bool can_shutdown() { return false; }
|
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 11:01:09 +00:00
|
|
|
|
2021-03-13 10:00:13 +00: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; }
|
|
|
|
|
|
|
|
void enumerate_static_tables(Function<void(const StringView&, PhysicalAddress, size_t)>);
|
|
|
|
|
2020-11-07 19:06:41 +00:00
|
|
|
virtual bool have_8042() const
|
|
|
|
{
|
|
|
|
return m_x86_specific_flags.keyboard_8042;
|
|
|
|
}
|
|
|
|
|
2020-04-09 16:15:02 +00: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 11:18:52 +00: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 11:01:09 +00:00
|
|
|
virtual void enable_aml_interpretation();
|
|
|
|
virtual void enable_aml_interpretation(File&);
|
|
|
|
virtual void enable_aml_interpretation(u8*, u32);
|
|
|
|
virtual void disable_aml_interpretation();
|
|
|
|
|
|
|
|
protected:
|
2020-04-09 16:15:02 +00:00
|
|
|
explicit Parser(PhysicalAddress rsdp);
|
2021-04-15 17:43:29 +00:00
|
|
|
virtual ~Parser() = default;
|
2020-04-09 12:10:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void set_the(Parser&);
|
2020-04-09 16:15:02 +00: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);
|
|
|
|
void init_fadt();
|
|
|
|
void init_facs();
|
|
|
|
|
|
|
|
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;
|
|
|
|
PhysicalAddress m_facs;
|
|
|
|
|
|
|
|
bool m_xsdt_supported { false };
|
|
|
|
FADTFlags::HardwareFeatures m_hardware_flags;
|
|
|
|
FADTFlags::x86_Specific_Flags m_x86_specific_flags;
|
2020-02-09 16:15:58 +00:00
|
|
|
};
|
2020-04-09 12:10:44 +00:00
|
|
|
|
2020-02-28 20:24:10 +00:00
|
|
|
}
|