forked from Bananymous/banan-os
Kernel: Map all ACPI tables on initialization
This makes their usage much easier and less error prone They won't mapped be processes when we get to there, so this won't be a problem
This commit is contained in:
parent
1c22e90fa0
commit
88f60b5e41
|
@ -84,8 +84,7 @@ namespace Kernel
|
|||
static BAN::ErrorOr<void> initialize();
|
||||
static ACPI& get();
|
||||
|
||||
BAN::ErrorOr<const SDTHeader*> get_header(const char[4]);
|
||||
void unmap_header(const SDTHeader*);
|
||||
const SDTHeader* get_header(const char[4]);
|
||||
|
||||
private:
|
||||
ACPI() = default;
|
||||
|
|
|
@ -135,28 +135,25 @@ namespace Kernel
|
|||
|
||||
MMU::get().allocate_range(m_header_table, m_entry_count * m_entry_size, MMU::Flags::Present);
|
||||
|
||||
for (uint32_t i = 0; i < m_entry_count; i++)
|
||||
{
|
||||
auto* header = get_header_from_index(i);
|
||||
MMU::get().allocate_page((uintptr_t)header, MMU::Flags::Present);
|
||||
MMU::get().allocate_range((uintptr_t)header, header->length, MMU::Flags::Present);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<const ACPI::SDTHeader*> ACPI::get_header(const char signature[4])
|
||||
const ACPI::SDTHeader* ACPI::get_header(const char signature[4])
|
||||
{
|
||||
for (uint32_t i = 0; i < m_entry_count; i++)
|
||||
{
|
||||
const SDTHeader* header = get_header_from_index(i);
|
||||
MMU::get().allocate_range((uintptr_t)header, header->length, MMU::Flags::Present);
|
||||
if (is_valid_std_header(header) && memcmp(header->signature, signature, 4) == 0)
|
||||
return header;
|
||||
unmap_header(header);
|
||||
}
|
||||
return BAN::Error::from_error_code(ErrorCode::ACPI_NoSuchHeader);
|
||||
}
|
||||
|
||||
void ACPI::unmap_header(const ACPI::SDTHeader* header)
|
||||
{
|
||||
// I have to improve MMU page mapping so we can actually unmap
|
||||
// without unmapping other mapped tables
|
||||
(void)header;
|
||||
//MMU::get().unallocate_range((uintptr_t)header, header->length);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const ACPI::SDTHeader* ACPI::get_header_from_index(size_t index)
|
||||
|
|
|
@ -91,15 +91,13 @@ APIC* APIC::create()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto header_or_error = Kernel::ACPI::get().get_header("APIC");
|
||||
if (header_or_error.is_error())
|
||||
const MADT* madt = (const MADT*)Kernel::ACPI::get().get_header("APIC");
|
||||
if (madt == nullptr)
|
||||
{
|
||||
dprintln("{}", header_or_error.error());
|
||||
dprintln("Could not find MADT header");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const MADT* madt = (const MADT*)header_or_error.value();
|
||||
|
||||
APIC* apic = new APIC;
|
||||
apic->m_local_apic = madt->local_apic;
|
||||
for (uint32_t i = 0x00; i <= 0xFF; i++)
|
||||
|
@ -139,8 +137,6 @@ APIC* APIC::create()
|
|||
madt_entry_addr += entry->length;
|
||||
}
|
||||
|
||||
Kernel::ACPI::get().unmap_header(madt);
|
||||
|
||||
if (apic->m_local_apic == 0 || apic->m_io_apics.empty())
|
||||
{
|
||||
dprintln("MADT did not provide necessary information");
|
||||
|
|
Loading…
Reference in New Issue