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_tfind (const char *signature)
 Finds a table with the given signature.
 

Detailed Description

Handles ACPI table parsing and retrieval.

Definition at line 99 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 Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
static Logger INFO()
Gets active logger set to info level.
Definition logger.cpp:171
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100
Root System Description Pointer (RSDP) structure for ACPI 2 and above.
Definition acpi.h:44
Root System Description Pointer (RSDP) structure for ACPI 1.
Definition acpi.h:29
Root System Description Table (RSDT) structure for ACPI 1. Contains the header and an array of pointe...
Definition acpi.h:78
Extended System Description Table (XSDT) structure for ACPI 2 and above. Contains the header and an a...
Definition acpi.h:90

References ASSERT, MaxOS::Logger::DEBUG(), and MaxOS::Logger::INFO().

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
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:915
bool strncmp(char const *str1, char const *str2, int length)
Checks if one string pointer is equal to another string pointer up to a specified length (each must b...
Definition string.cpp:826
Common header for all ACPI System Description Tables (SDTs)
Definition acpi.h:59
uint64_t pointers[]
An array of physical addresses pointing to other ACPI SDTs.
Definition acpi.h:92

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

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


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