Kernel: Allow getting ACPI headers with same signature

This commit is contained in:
Bananymous 2023-10-13 11:24:21 +03:00
parent 72f3c378dd
commit f842a9255f
5 changed files with 14 additions and 8 deletions

View File

@ -108,7 +108,7 @@ namespace Kernel
static BAN::ErrorOr<void> initialize(); static BAN::ErrorOr<void> initialize();
static ACPI& get(); static ACPI& get();
const SDTHeader* get_header(const char[4]); const SDTHeader* get_header(BAN::StringView signature, uint32_t index);
private: private:
ACPI() = default; ACPI() = default;

View File

@ -222,12 +222,19 @@ namespace Kernel
return {}; return {};
} }
const ACPI::SDTHeader* ACPI::get_header(const char signature[4]) const ACPI::SDTHeader* ACPI::get_header(BAN::StringView signature, uint32_t index)
{ {
if (signature.size() != 4)
{
dprintln("Trying to get ACPI header with {} byte signature ??", signature.size());
return nullptr;
}
uint32_t cnt = 0;
for (auto& mapped_header : m_mapped_headers) for (auto& mapped_header : m_mapped_headers)
{ {
auto* header = mapped_header.as_header(); auto* header = mapped_header.as_header();
if (memcmp(header->signature, signature, 4) == 0) if (memcmp(header->signature, signature.data(), 4) == 0)
if (cnt++ == index)
return header; return header;
} }
return nullptr; return nullptr;

View File

@ -95,7 +95,7 @@ namespace Kernel
return nullptr; return nullptr;
} }
const MADT* madt = (const MADT*)Kernel::ACPI::get().get_header("APIC"); const MADT* madt = (const MADT*)Kernel::ACPI::get().get_header("APIC"sv, 0);
if (madt == nullptr) if (madt == nullptr)
{ {
dprintln("Could not find MADT header"); dprintln("Could not find MADT header");

View File

@ -46,7 +46,7 @@ namespace Kernel
BAN::ErrorOr<void> HPET::initialize(bool force_pic) BAN::ErrorOr<void> HPET::initialize(bool force_pic)
{ {
auto* header = (ACPI::HPET*)ACPI::get().get_header("HPET"); auto* header = (ACPI::HPET*)ACPI::get().get_header("HPET"sv, 0);
if (header == nullptr) if (header == nullptr)
return BAN::Error::from_errno(ENODEV); return BAN::Error::from_errno(ENODEV);

View File

@ -51,8 +51,7 @@ void laihost_panic(const char* msg)
void* laihost_scan(const char* sig, size_t index) void* laihost_scan(const char* sig, size_t index)
{ {
ASSERT(index == 0); return (void*)ACPI::get().get_header(sig, index);
return (void*)ACPI::get().get_header(sig);
} }
void* laihost_map(size_t address, size_t count) void* laihost_map(size_t address, size_t count)