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:
parent
abcf1b6118
commit
533b7c9e71
@ -9,26 +9,28 @@
|
|||||||
|
|
||||||
extern BOOTBOOT bootboot;
|
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;
|
static SDTHeader* cache = nullptr;
|
||||||
if (cache) return (SDTHeader*)cache;
|
if (cache) return cache;
|
||||||
|
|
||||||
kdbgln("First time accessing the RSDT/XSDT, mapping it into memory");
|
kdbgln("First time accessing the RSDT/XSDT, mapping it into memory");
|
||||||
void* physical = (void*)bootboot.arch.x86_64.acpi_ptr;
|
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);
|
kdbgln("RSDT/XSDT physical address: %lx", (uint64_t)physical);
|
||||||
cache = MemoryManager::get_unaligned_mapping(physical);
|
|
||||||
uint64_t numPages = 1;
|
cache = (SDTHeader*)MemoryManager::get_unaligned_mapping(physical);
|
||||||
while ((offset + ((SDTHeader*)cache)->Length) > (numPages * PAGE_SIZE))
|
|
||||||
|
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_mapping(cache);
|
||||||
MemoryManager::release_unaligned_mappings(cache, numPages);
|
cache = (SDTHeader*)MemoryManager::get_unaligned_mappings(cache, rsdt_pages);
|
||||||
numPages++;
|
|
||||||
cache = MemoryManager::get_unaligned_mappings(cache, numPages);
|
|
||||||
}
|
}
|
||||||
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, numPages);
|
|
||||||
SDTHeader* result = (SDTHeader*)cache;
|
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, rsdt_pages);
|
||||||
return result;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ACPI::validate_rsdt_or_xsdt(ACPI::SDTHeader* root_sdt)
|
bool ACPI::validate_rsdt_or_xsdt(ACPI::SDTHeader* root_sdt)
|
||||||
|
@ -48,8 +48,7 @@ void PMM::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitmap_addr = (char*)biggest_chunk;
|
bitmap_addr = (char*)biggest_chunk;
|
||||||
virtual_bitmap_addr =
|
virtual_bitmap_addr = bitmap_addr;
|
||||||
bitmap_addr; // FIXME: map this to a virtual address (ideally in the kernel heap between -128M and -64M)
|
|
||||||
ASSERT((total_mem / PAGE_SIZE / 8) < biggest_chunk_size);
|
ASSERT((total_mem / PAGE_SIZE / 8) < biggest_chunk_size);
|
||||||
bitmap_size = total_mem / PAGE_SIZE / 8 + 1;
|
bitmap_size = total_mem / PAGE_SIZE / 8 + 1;
|
||||||
memset(bitmap_addr, 0xFF, bitmap_size);
|
memset(bitmap_addr, 0xFF, bitmap_size);
|
||||||
|
Loading…
Reference in New Issue
Block a user