Refactor ACPI::get_rsdt_or_xsdt()

Much better now.

Also, remove a FIXME in PMM.cpp, since we do map the page bitmap to virtual memory now.
This commit is contained in:
apio 2022-10-08 15:00:42 +02:00
parent abcf1b6118
commit 533b7c9e71
2 changed files with 17 additions and 16 deletions

View File

@ -9,26 +9,28 @@
extern BOOTBOOT bootboot;
ACPI::SDTHeader* ACPI::get_rsdt_or_xsdt() // FIXME: Refactor this ugly code.
ACPI::SDTHeader* ACPI::get_rsdt_or_xsdt()
{
static void* cache = nullptr;
if (cache) return (SDTHeader*)cache;
static SDTHeader* cache = nullptr;
if (cache) return cache;
kdbgln("First time accessing the RSDT/XSDT, mapping it into memory");
void* physical = (void*)bootboot.arch.x86_64.acpi_ptr;
uint64_t offset = (uint64_t)physical % PAGE_SIZE;
kdbgln("RSDT/XSDT physical address: %lx", (uint64_t)physical);
cache = MemoryManager::get_unaligned_mapping(physical);
uint64_t numPages = 1;
while ((offset + ((SDTHeader*)cache)->Length) > (numPages * PAGE_SIZE))
cache = (SDTHeader*)MemoryManager::get_unaligned_mapping(physical);
uint64_t offset = (uint64_t)physical % PAGE_SIZE;
uint64_t rsdt_pages = (offset + cache->Length) / PAGE_SIZE;
if (rsdt_pages > 1)
{
kwarnln("RSDT/XSDT extends beyond the mapped page, mapping one more page");
MemoryManager::release_unaligned_mappings(cache, numPages);
numPages++;
cache = MemoryManager::get_unaligned_mappings(cache, numPages);
MemoryManager::release_unaligned_mapping(cache);
cache = (SDTHeader*)MemoryManager::get_unaligned_mappings(cache, rsdt_pages);
}
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, numPages);
SDTHeader* result = (SDTHeader*)cache;
return result;
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, rsdt_pages);
return cache;
}
bool ACPI::validate_rsdt_or_xsdt(ACPI::SDTHeader* root_sdt)

View File

@ -48,8 +48,7 @@ void PMM::init()
}
bitmap_addr = (char*)biggest_chunk;
virtual_bitmap_addr =
bitmap_addr; // FIXME: map this to a virtual address (ideally in the kernel heap between -128M and -64M)
virtual_bitmap_addr = bitmap_addr;
ASSERT((total_mem / PAGE_SIZE / 8) < biggest_chunk_size);
bitmap_size = total_mem / PAGE_SIZE / 8 + 1;
memset(bitmap_addr, 0xFF, bitmap_size);