Serenity Operating System
1/*
2 * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AK/Types.h>
30#include <Kernel/ACPI/Definitions.h>
31#include <Kernel/ACPI/Initialize.h>
32#include <Kernel/FileSystem/File.h>
33#include <Kernel/VM/Region.h>
34#include <LibBareMetal/Memory/PhysicalAddress.h>
35#include <LibBareMetal/Memory/VirtualAddress.h>
36
37namespace Kernel {
38namespace ACPI {
39
40class Parser {
41public:
42 static Parser* the();
43
44 template<typename ParserType>
45 static void initialize(PhysicalAddress rsdp)
46 {
47 set_the(*new ParserType(rsdp));
48 }
49
50 virtual PhysicalAddress find_table(const StringView& signature);
51
52 virtual void try_acpi_reboot();
53 virtual bool can_reboot();
54 virtual void try_acpi_shutdown();
55 virtual bool can_shutdown() { return false; }
56
57 const FADTFlags::HardwareFeatures& hardware_features() const { return m_hardware_flags; }
58 const FADTFlags::x86_Specific_Flags& x86_specific_flags() const { return m_x86_specific_flags; }
59
60 virtual void enable_aml_interpretation();
61 virtual void enable_aml_interpretation(File&);
62 virtual void enable_aml_interpretation(u8*, u32);
63 virtual void disable_aml_interpretation();
64
65protected:
66 explicit Parser(PhysicalAddress rsdp);
67
68private:
69 static void set_the(Parser&);
70
71 void locate_static_data();
72 void locate_main_system_description_table();
73 void initialize_main_system_description_table();
74 size_t get_table_size(PhysicalAddress);
75 u8 get_table_revision(PhysicalAddress);
76 void init_fadt();
77 void init_facs();
78
79 bool validate_reset_register();
80 void access_generic_address(const Structures::GenericAddressStructure&, u32 value);
81
82 PhysicalAddress m_rsdp;
83 PhysicalAddress m_main_system_description_table;
84
85 Vector<PhysicalAddress> m_sdt_pointers;
86 PhysicalAddress m_fadt;
87 PhysicalAddress m_facs;
88
89 bool m_xsdt_supported { false };
90 FADTFlags::HardwareFeatures m_hardware_flags;
91 FADTFlags::x86_Specific_Flags m_x86_specific_flags;
92};
93
94}
95}