Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::hardwarecommunication::AdvancedConfigurationAndPowerInterface Class Reference

Handles ACPI table parsing and retrieval. More...

#include <acpi.h>

Public Member Functions

 AdvancedConfigurationAndPowerInterface (system::Multiboot *multiboot)
 Construct a new Advanced Configuration And Power Interface object. Maps the ACPI headers and tables into the higher half.
 
acpi_sdt_header_t * find (const char *signature)
 Finds a table with the given signature.
 

Detailed Description

Handles ACPI table parsing and retrieval.

Definition at line 102 of file acpi.h.

Constructor & Destructor Documentation

◆ AdvancedConfigurationAndPowerInterface()

AdvancedConfigurationAndPowerInterface::AdvancedConfigurationAndPowerInterface ( system::Multiboot *  multiboot)
explicit

Construct a new Advanced Configuration And Power Interface object. Maps the ACPI headers and tables into the higher half.

Parameters
multibootThe multiboot information structure to get the ACPI information from

Definition at line 23 of file acpi.cpp.

24: m_header(nullptr) {
25
26 Logger::INFO() << "Setting up ACPI\n";
27
28 // If the new ACPI is not supported, panic
29 ASSERT(multiboot->new_acpi() != nullptr || multiboot->old_acpi() != nullptr, "No ACPI found!");
30
31 // Check if the new ACPI is supported
32 m_using_new_acpi = multiboot->old_acpi() == nullptr;
33 Logger::DEBUG() << "CPU Supports " << (m_using_new_acpi ? "New" : "Old") << " ACPI\n";
34
35 if(m_using_new_acpi)
36 m_rsdp2 = (RSDPDescriptor2*) (multiboot->new_acpi() + 1);
37 else
38 m_rsdp = (RSDPDescriptor*) (multiboot->old_acpi() + 1);
39
40 // Map the XSDT/RSDT
41 uint64_t physical_address = m_using_new_acpi ? m_rsdp2->xsdt_address : m_rsdp->rsdt_address;
42 void* virtual_address = map_descriptor(physical_address);
43 ASSERT(virtual_address != nullptr, "Failed to map ACPI table");
44 Logger::DEBUG() << "XSDT/RSDT: physical: 0x" << physical_address << ", virtual: 0x" << (uint64_t) virtual_address
45 << "\n";
46
47 // Load
48 if(m_using_new_acpi)
49 m_xsdt = (XSDT*) virtual_address;
50 else
51 m_rsdt = (RSDT*) virtual_address;
52
53 // Map the Tables
54 Logger::DEBUG() << "Mapping ACPI Tables\n";
55 map_tables(m_using_new_acpi ? sizeof(uint64_t) : sizeof(uint32_t));
56
57 // Check if the checksum is valid
58 ASSERT(valid_checksum(), "ACPI: Invalid checksum!");
59}
static LogRecord DEBUG()
Gets the active logger for debug logs.
Definition logger.cpp:204
static LogRecord INFO()
Gets the active logger for info logs.
Definition logger.cpp:195
multiboot_tag_old_acpi * old_acpi()
Get the old ACPI tag.
multiboot_tag_new_acpi * new_acpi()
Get the new ACPI tag.
Root System Description Pointer (RSDP) structure for ACPI 2 and above.
Definition acpi.h:47
Root System Description Pointer (RSDP) structure for ACPI 1.
Definition acpi.h:32
Root System Description Table (RSDT) structure for ACPI 1. Contains the header and an array of pointe...
Definition acpi.h:81
Extended System Description Table (XSDT) structure for ACPI 2 and above. Contains the header and an a...
Definition acpi.h:93

References MaxOS::Logger::DEBUG(), MaxOS::Logger::INFO(), MaxOS::system::Multiboot::new_acpi(), and MaxOS::system::Multiboot::old_acpi().

Member Function Documentation

◆ find()

ACPISDTHeader * AdvancedConfigurationAndPowerInterface::find ( const char *  signature)

Finds a table with the given signature.

Parameters
signatureThe signature to search for
Returns
The table with the given signature, or nullptr if not found

Definition at line 163 of file acpi.cpp.

163 {
164
165 // Get the number of entries
166 size_t entries = (m_header->length - sizeof(ACPISDTHeader)) / sizeof(uint32_t);
167 if(m_using_new_acpi) entries = (m_header->length - sizeof(ACPISDTHeader)) / sizeof(uint64_t);
168
169 // Loop through all the entries
170 for(size_t i = 0; i < entries; ++i) {
171
172 // Get the entry
173 auto* header = (ACPISDTHeader*) (m_using_new_acpi ? m_xsdt->pointers[i] : get_rsdt_pointer(i));
174
175 // Move the header to the higher half
176 header = (ACPISDTHeader*) PhysicalMemoryManager::to_io_region((uint64_t) header);
177
178 // Check if the signature matches
179 if(strncmp(header->signature, signature, 4))
180 return header;
181 }
182
183 // Return null if no entry was found
184 return nullptr;
185}
static void * to_io_region(uintptr_t physical_address)
Converts a physical address to an IO region address if it is in the lower region using the higher hal...
Definition physical.cpp:914
Common header for all ACPI System Description Tables (SDTs)
Definition acpi.h:62
uint64_t pointers[]
An array of physical addresses pointing to other ACPI SDTs.
Definition acpi.h:95

References MaxOS::hardwarecommunication::XSDT::pointers, and MaxOS::memory::PhysicalMemoryManager::to_io_region().

Referenced by MaxOS::hardwarecommunication::IOAPIC::IOAPIC().


The documentation for this class was generated from the following files: