mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
Kernel: Remove problematic memory mapping methods
mmap() & mmap_region() methods are removed from ACPI & DMI components, and we replace them with the new MM.allocate_kernel_region() helper. Instead of doing a raw calculation for each VM address, from now on we can use helper functions to do perform those calculations in a neat, reusable and readable way.
This commit is contained in:
parent
d2b41010c5
commit
a9884fbbe5
10 changed files with 117 additions and 160 deletions
|
@ -36,16 +36,6 @@ ACPI_RAW::SDTHeader* ACPIParser::find_table(const char*)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void ACPIParser::mmap(VirtualAddress, PhysicalAddress, u32)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void ACPIParser::mmap_region(Region&, PhysicalAddress)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void ACPIParser::do_acpi_reboot()
|
||||
{
|
||||
kprintf("ACPI: Cannot invoke reboot!\n");
|
||||
|
|
|
@ -27,7 +27,4 @@ public:
|
|||
protected:
|
||||
explicit ACPIParser(bool usable);
|
||||
bool m_operable;
|
||||
|
||||
virtual void mmap(VirtualAddress, PhysicalAddress, u32);
|
||||
virtual void mmap_region(Region&, PhysicalAddress);
|
||||
};
|
|
@ -3,6 +3,8 @@
|
|||
#include <Kernel/StdLib.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
|
||||
//#define ACPI_DEBUG
|
||||
|
||||
void ACPIStaticParser::initialize(ACPI_RAW::RSDPDescriptor20& rsdp)
|
||||
{
|
||||
if (!ACPIParser::is_initialized()) {
|
||||
|
@ -35,9 +37,8 @@ ACPI_RAW::SDTHeader* ACPIStaticParser::find_table(const char* sig)
|
|||
dbgprintf("ACPI: Calling Find Table method!\n");
|
||||
#endif
|
||||
for (auto* physical_sdt_ptr : m_main_sdt->get_sdt_pointers()) {
|
||||
auto region = MM.allocate_kernel_region((PAGE_SIZE * 2), "ACPI Static Parser Tables Finding", Region::Access::Read);
|
||||
mmap_region(*region, PhysicalAddress((u32)physical_sdt_ptr));
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)(region->vaddr().get() + ((u32)physical_sdt_ptr & (~PAGE_MASK)));
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)physical_sdt_ptr)), (PAGE_SIZE * 2), "ACPI Static Parser Tables Finding", Region::Access::Read);
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)region->vaddr().offset(offset_in_page((u32)physical_sdt_ptr)).as_ptr();
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Examining Table @ P 0x%x\n", physical_sdt_ptr);
|
||||
#endif
|
||||
|
@ -51,45 +52,27 @@ ACPI_RAW::SDTHeader* ACPIStaticParser::find_table(const char* sig)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ACPI_RAW::SDTHeader& ACPIStaticParser::find_fadt()
|
||||
{
|
||||
kprintf("ACPI: Searching for the Fixed ACPI Data Table\n");
|
||||
for (auto* physical_sdt_ptr : m_main_sdt->get_sdt_pointers()) {
|
||||
auto region = MM.allocate_kernel_region((PAGE_SIZE * 2), "ACPI Static Parser AML Tables Finding", Region::Access::Read);
|
||||
mmap_region(*region, PhysicalAddress((u32)physical_sdt_ptr & PAGE_MASK));
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)(region->vaddr().get() + ((u32)physical_sdt_ptr & (~PAGE_MASK)));
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Examining Table @ P 0x%x\n", physical_sdt_ptr);
|
||||
#endif
|
||||
if (!strncmp(sdt->sig, "FACP", 4)) {
|
||||
kprintf("ACPI: Found FADT Table @ P 0x%x, registering\n", physical_sdt_ptr);
|
||||
return *physical_sdt_ptr;
|
||||
}
|
||||
}
|
||||
ASSERT_NOT_REACHED(); // If we reached this point, there's something very incorrect with the system!
|
||||
}
|
||||
|
||||
void ACPIStaticParser::init_fadt()
|
||||
{
|
||||
kprintf("ACPI: Initializing Fixed ACPI data\n");
|
||||
ACPI_RAW::SDTHeader& physical_fadt = find_fadt();
|
||||
kprintf("ACPI: Searching for the Fixed ACPI Data Table\n");
|
||||
ASSERT(find_table("FACP") != nullptr);
|
||||
auto* fadt_ptr = find_table("FACP");
|
||||
|
||||
auto checkup_region = MM.allocate_kernel_region((PAGE_SIZE * 2), "ACPI Static Parser", Region::Access::Read);
|
||||
auto checkup_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)(fadt_ptr))), (PAGE_SIZE * 2), "ACPI Static Parser", Region::Access::Read);
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Checking FADT Length to choose the correct mapping size\n");
|
||||
#endif
|
||||
mmap_region(*checkup_region, PhysicalAddress((u32)(&physical_fadt) & PAGE_MASK));
|
||||
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)(checkup_region->vaddr().get() + ((u32)(&physical_fadt) & (~PAGE_MASK)));
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)checkup_region->vaddr().offset(offset_in_page((u32)(fadt_ptr))).as_ptr();
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: FADT @ V 0x%x, P 0x%x\n", sdt, &physical_fadt);
|
||||
dbgprintf("ACPI: FADT @ V 0x%x, P 0x%x\n", sdt, fadt_ptr);
|
||||
#endif
|
||||
u32 length = sdt->length;
|
||||
kprintf("ACPI: Fixed ACPI data, Revision %u\n", sdt->revision);
|
||||
|
||||
auto fadt_region = MM.allocate_kernel_region(PAGE_ROUND_UP(length) + PAGE_SIZE, "ACPI Static Parser", Region::Access::Read);
|
||||
mmap_region(*fadt_region, PhysicalAddress((u32)(&physical_fadt) & PAGE_MASK));
|
||||
m_fadt = OwnPtr<ACPI::FixedACPIData>(new ACPI::FixedACPIData(*((ACPI_RAW::FADT*)(fadt_region->vaddr().get() + ((u32)(&physical_fadt) & (~PAGE_MASK))))));
|
||||
auto fadt_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)(fadt_ptr))), PAGE_ROUND_UP(length) + PAGE_SIZE, "ACPI Static Parser", Region::Access::Read);
|
||||
m_fadt = make<ACPI::FixedACPIData>(*(ACPI_RAW::FADT*)fadt_region->vaddr().offset(offset_in_page((u32)(fadt_ptr))).as_ptr());
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Finished to initialize Fixed ACPI data\n");
|
||||
#endif
|
||||
|
@ -117,39 +100,83 @@ void ACPIStaticParser::do_acpi_shutdown()
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
inline bool validate_acpi_table(ACPI_RAW::SDTHeader& v_header, size_t length)
|
||||
{
|
||||
u8 checksum = 0;
|
||||
auto* sdt = (u8*)&v_header;
|
||||
for (size_t i = 0; i < length; i++)
|
||||
checksum += sdt[i];
|
||||
if (checksum == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ACPIStaticParser::get_table_size(ACPI_RAW::SDTHeader& p_header)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Checking SDT Length\n");
|
||||
#endif
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress((u32)&p_header & PAGE_MASK), (PAGE_SIZE * 2), "ACPI get_table_size()", Region::Access::Read);
|
||||
volatile auto* sdt = (ACPI_RAW::SDTHeader*)region->vaddr().offset(offset_in_page((u32)&p_header)).as_ptr();
|
||||
return sdt->length;
|
||||
}
|
||||
|
||||
u8 ACPIStaticParser::get_table_revision(ACPI_RAW::SDTHeader& p_header)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Checking SDT Revision\n");
|
||||
#endif
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress((u32)&p_header & PAGE_MASK), (PAGE_SIZE * 2), "ACPI get_table_revision()", Region::Access::Read);
|
||||
volatile auto* sdt = (ACPI_RAW::SDTHeader*)region->vaddr().offset(offset_in_page((u32)&p_header)).as_ptr();
|
||||
return sdt->revision;
|
||||
}
|
||||
|
||||
void ACPIStaticParser::initialize_main_system_description_table()
|
||||
{
|
||||
auto checkup_region = MM.allocate_kernel_region((PAGE_SIZE * 2), "ACPI Static Parser Copying Method", Region::Access::Read);
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Checking Main SDT Length to choose the correct mapping size");
|
||||
dbgprintf("ACPI: Checking Main SDT Length to choose the correct mapping size\n");
|
||||
#endif
|
||||
mmap_region(*checkup_region, PhysicalAddress((u32)m_main_system_description_table & PAGE_MASK));
|
||||
ASSERT(m_main_system_description_table != nullptr);
|
||||
u32 length;
|
||||
u8 revision;
|
||||
if (m_xsdt_supported) {
|
||||
length = get_table_size(*m_main_system_description_table);
|
||||
revision = get_table_revision(*m_main_system_description_table);
|
||||
} else {
|
||||
length = get_table_size(*m_main_system_description_table);
|
||||
revision = get_table_revision(*m_main_system_description_table);
|
||||
}
|
||||
|
||||
auto* sdt = (ACPI_RAW::SDTHeader*)(checkup_region->vaddr().get() + ((u32)m_main_system_description_table & (~PAGE_MASK)));
|
||||
u32 length = sdt->length;
|
||||
u8 revision = sdt->revision;
|
||||
|
||||
auto main_sdt_region = MM.allocate_kernel_region(PAGE_ROUND_UP(length) + PAGE_SIZE, "ACPI Static Parser Copying Method", Region::Access::Read);
|
||||
mmap_region(*main_sdt_region, PhysicalAddress((u32)m_main_system_description_table & PAGE_MASK));
|
||||
auto main_sdt_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)m_main_system_description_table)), PAGE_ROUND_UP(length) + PAGE_SIZE, "ACPI Static Parser Initialization", Region::Access::Read, false, true);
|
||||
volatile auto* sdt = (ACPI_RAW::SDTHeader*)main_sdt_region->vaddr().offset(offset_in_page((u32)m_main_system_description_table)).as_ptr();
|
||||
kprintf("ACPI: Main Description Table valid? 0x%x\n", validate_acpi_table(const_cast<ACPI_RAW::SDTHeader&>(*sdt), length));
|
||||
|
||||
Vector<ACPI_RAW::SDTHeader*> sdt_pointers;
|
||||
if (m_xsdt_supported) {
|
||||
ACPI_RAW::XSDT* xsdt = (ACPI_RAW::XSDT*)(main_sdt_region->vaddr().get() + ((u32)m_main_system_description_table & (~PAGE_MASK)));
|
||||
volatile auto* xsdt = (volatile ACPI_RAW::XSDT*)sdt;
|
||||
kprintf("ACPI: Using XSDT, Enumerating tables @ P 0x%x\n", m_main_system_description_table);
|
||||
kprintf("ACPI: XSDT Revision %d, Total length - %u\n", revision, length);
|
||||
for (u32 i = 0; i < ((xsdt->h.length - sizeof(ACPI_RAW::SDTHeader)) / sizeof(u64)); i++) {
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Found new table, @ P 0x%x\n", xsdt->table_ptrs[i]);
|
||||
dbgprintf("ACPI: XSDT pointer @ V 0x%x\n", xsdt);
|
||||
#endif
|
||||
for (u32 i = 0; i < ((length - sizeof(ACPI_RAW::SDTHeader)) / sizeof(u64)); i++) {
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Found new table [%u], @ V0x%x - P0x%x\n", i, &xsdt->table_ptrs[i], xsdt->table_ptrs[i]);
|
||||
#endif
|
||||
sdt_pointers.append((ACPI_RAW::SDTHeader*)xsdt->table_ptrs[i]);
|
||||
}
|
||||
} else {
|
||||
ACPI_RAW::RSDT* rsdt = (ACPI_RAW::RSDT*)(main_sdt_region->vaddr().get() + ((u32)m_main_system_description_table & (~PAGE_MASK)));
|
||||
volatile auto* rsdt = (volatile ACPI_RAW::RSDT*)sdt;
|
||||
kprintf("ACPI: Using RSDT, Enumerating tables @ P 0x%x\n", m_main_system_description_table);
|
||||
kprintf("ACPI: RSDT Revision %d, Total length - %u\n", revision, length);
|
||||
for (u32 i = 0; i < ((rsdt->h.length - sizeof(ACPI_RAW::SDTHeader)) / sizeof(u32)); i++) {
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Found new table, @ P 0x%x\n", rsdt->table_ptrs[i]);
|
||||
dbgprintf("ACPI: RSDT pointer @ V 0x%x\n", rsdt);
|
||||
#endif
|
||||
for (u32 i = 0; i < ((length - sizeof(ACPI_RAW::SDTHeader)) / sizeof(u32)); i++) {
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Found new table [%u], @ V0x%x - P0x%x\n", i, &rsdt->table_ptrs[i], rsdt->table_ptrs[i]);
|
||||
#endif
|
||||
sdt_pointers.append((ACPI_RAW::SDTHeader*)rsdt->table_ptrs[i]);
|
||||
}
|
||||
|
@ -183,9 +210,8 @@ void ACPIStaticParser::locate_all_aml_tables()
|
|||
kprintf("ACPI: Searching for AML Tables\n");
|
||||
m_aml_tables_ptrs.append(m_fadt->get_dsdt());
|
||||
for (auto* sdt_ptr : m_main_sdt->get_sdt_pointers()) {
|
||||
auto region = MM.allocate_kernel_region((PAGE_SIZE * 2), "ACPI Static Parser AML Tables Finding", Region::Access::Read);
|
||||
mmap_region(*region, PhysicalAddress((u32)sdt_ptr));
|
||||
auto* sdt = (ACPI_RAW::SDTHeader*)(region->vaddr().get() + ((u32)sdt_ptr & (~PAGE_MASK)));
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)sdt_ptr)), (PAGE_SIZE * 2), "ACPI Static Parser AML Tables Finding", Region::Access::Read);
|
||||
auto* sdt = (ACPI_RAW::SDTHeader*)region->vaddr().offset(offset_in_page((u32)sdt_ptr)).as_ptr();
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Examining Table @ P 0x%x\n", sdt_ptr);
|
||||
#endif
|
||||
|
@ -215,8 +241,7 @@ ACPIStaticParser::ACPIStaticParser()
|
|||
|
||||
ACPI_RAW::RSDPDescriptor20* ACPIStaticParser::search_rsdp()
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(PAGE_SIZE, "ACPI Static Parser RSDP Finding", Region::Access::Read);
|
||||
mmap_region(*region, PhysicalAddress(0));
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress(0), PAGE_SIZE, "ACPI Static Parser RSDP Finding", Region::Access::Read);
|
||||
u16 ebda_seg = (u16) * ((uint16_t*)((region->vaddr().get() & PAGE_MASK) + 0x40e));
|
||||
kprintf("ACPI: Probing EBDA, Segment 0x%x\n", ebda_seg);
|
||||
|
||||
|
@ -240,33 +265,6 @@ ACPI_RAW::RSDPDescriptor20* ACPIStaticParser::search_rsdp()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void ACPIStaticParser::mmap(VirtualAddress vaddr, PhysicalAddress paddr, u32 length)
|
||||
{
|
||||
unsigned i = 0;
|
||||
while (length >= PAGE_SIZE) {
|
||||
MM.map_for_kernel(VirtualAddress(vaddr.offset(i * PAGE_SIZE).get()), PhysicalAddress(paddr.offset(i * PAGE_SIZE).get()));
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: map - V 0x%x -> P 0x%x\n", vaddr.offset(i * PAGE_SIZE).get(), paddr.offset(i * PAGE_SIZE).get());
|
||||
#endif
|
||||
length -= PAGE_SIZE;
|
||||
i++;
|
||||
}
|
||||
if (length > 0) {
|
||||
MM.map_for_kernel(vaddr.offset(i * PAGE_SIZE), paddr.offset(i * PAGE_SIZE), true);
|
||||
}
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Finished mapping\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void ACPIStaticParser::mmap_region(Region& region, PhysicalAddress paddr)
|
||||
{
|
||||
#ifdef ACPI_DEBUG
|
||||
dbgprintf("ACPI: Mapping region, size - %u\n", region.size());
|
||||
#endif
|
||||
mmap(region.vaddr(), paddr, region.size());
|
||||
}
|
||||
|
||||
ACPIStaticParser::ACPIStaticParser(ACPI_RAW::RSDPDescriptor20& rsdp)
|
||||
: ACPIParser(true)
|
||||
, m_rsdp(&rsdp)
|
||||
|
|
|
@ -18,15 +18,13 @@ protected:
|
|||
ACPIStaticParser();
|
||||
explicit ACPIStaticParser(ACPI_RAW::RSDPDescriptor20&);
|
||||
|
||||
virtual void mmap(VirtualAddress preferred_vaddr, PhysicalAddress paddr, u32) override;
|
||||
virtual void mmap_region(Region& region, PhysicalAddress paddr) override;
|
||||
|
||||
private:
|
||||
void locate_static_data();
|
||||
void locate_all_aml_tables();
|
||||
void locate_main_system_description_table();
|
||||
void initialize_main_system_description_table();
|
||||
ACPI_RAW::SDTHeader& find_fadt();
|
||||
size_t get_table_size(ACPI_RAW::SDTHeader&);
|
||||
u8 get_table_revision(ACPI_RAW::SDTHeader&);
|
||||
void init_fadt();
|
||||
ACPI_RAW::RSDPDescriptor20* search_rsdp();
|
||||
|
||||
|
|
|
@ -60,37 +60,40 @@ void DMIDecoder::initialize_parser()
|
|||
|
||||
void DMIDecoder::enumerate_smbios_tables()
|
||||
{
|
||||
|
||||
u32 table_length = m_table_length;
|
||||
SMBIOS::TableHeader* physical_table = m_structure_table;
|
||||
SMBIOS::TableHeader* p_table_ptr = m_structure_table;
|
||||
|
||||
auto region = MM.allocate_kernel_region(PAGE_ROUND_UP(table_length), "DMI Decoder Entry Point Finding", Region::Access::Read);
|
||||
PhysicalAddress paddr = PhysicalAddress((u32)physical_table & PAGE_MASK);
|
||||
mmap_region(*region, paddr);
|
||||
PhysicalAddress paddr = PhysicalAddress(page_base_of((u32)p_table_ptr));
|
||||
auto region = MM.allocate_kernel_region(paddr, PAGE_ROUND_UP(table_length), "DMI Decoder Enumerating SMBIOS", Region::Access::Read, false, false);
|
||||
|
||||
auto* v_smbios_table = (SMBIOS::TableHeader*)(region->vaddr().get() + ((u32)physical_table & (~PAGE_MASK)));
|
||||
volatile SMBIOS::TableHeader* v_table_ptr = (SMBIOS::TableHeader*)region->vaddr().offset(offset_in_page((u32)p_table_ptr)).as_ptr();
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMIDecoder: Total Table length %d\n", m_table_length);
|
||||
#endif
|
||||
|
||||
u32 structures_count = 0;
|
||||
while (table_length > 0) {
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMIDecoder: Examining table @ P 0x%x\n", physical_table);
|
||||
dbgprintf("DMIDecoder: Examining table @ P 0x%x V 0x%x\n", p_table_ptr, v_table_ptr);
|
||||
#endif
|
||||
structures_count++;
|
||||
if (v_smbios_table->type == (u32)SMBIOS::TableType::EndOfTable) {
|
||||
if (v_table_ptr->type == (u32)SMBIOS::TableType::EndOfTable) {
|
||||
kprintf("DMIDecoder: Detected table with type 127, End of SMBIOS data.\n");
|
||||
break;
|
||||
}
|
||||
m_smbios_tables.append(physical_table);
|
||||
table_length -= v_smbios_table->length;
|
||||
kprintf("DMIDecoder: Detected table with type %u\n", v_smbios_table->type);
|
||||
SMBIOS::TableHeader* physical_next_table = get_next_physical_table(*physical_table);
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMIDecoder: Next table @ P 0x%x\n", physical_next_table);
|
||||
#endif
|
||||
if (physical_next_table == nullptr)
|
||||
break;
|
||||
kprintf("DMIDecoder: Detected table with type %d\n", v_table_ptr->type);
|
||||
m_smbios_tables.append(p_table_ptr);
|
||||
table_length -= v_table_ptr->length;
|
||||
|
||||
v_smbios_table = (SMBIOS::TableHeader*)(region->vaddr().get() + (u32)physical_next_table - paddr.get());
|
||||
physical_table = physical_next_table;
|
||||
size_t table_size = get_table_size(*p_table_ptr);
|
||||
p_table_ptr = (SMBIOS::TableHeader*)((u32)p_table_ptr + (u32)table_size);
|
||||
v_table_ptr = (SMBIOS::TableHeader*)((u32)v_table_ptr + (u32)table_size);
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMIDecoder: Next table @ P 0x%x\n", p_table_ptr);
|
||||
#endif
|
||||
if (p_table_ptr == nullptr)
|
||||
break;
|
||||
}
|
||||
m_structures_count = structures_count;
|
||||
}
|
||||
|
@ -110,7 +113,7 @@ size_t DMIDecoder::get_table_size(SMBIOS::TableHeader& table)
|
|||
index++;
|
||||
}
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMIDecoder: table size - 0x%x\n", table.length + i + 1);
|
||||
dbgprintf("DMIDecoder: table size - 0x%x\n", table.length + index + 1);
|
||||
#endif
|
||||
return table.length + index + 1;
|
||||
}
|
||||
|
@ -122,14 +125,13 @@ SMBIOS::TableHeader* DMIDecoder::get_next_physical_table(SMBIOS::TableHeader& p_
|
|||
|
||||
SMBIOS::TableHeader* DMIDecoder::get_smbios_physical_table_by_handle(u16 handle)
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(PAGE_ROUND_UP(PAGE_SIZE * 2), "DMI Decoder Finding Table", Region::Access::Read);
|
||||
|
||||
for (auto* table : m_smbios_tables) {
|
||||
if (!table)
|
||||
continue;
|
||||
PhysicalAddress paddr = PhysicalAddress((u32)table & PAGE_MASK);
|
||||
mmap_region(*region, paddr);
|
||||
SMBIOS::TableHeader* table_v_ptr = (SMBIOS::TableHeader*)(region->vaddr().get() + ((u32)table & (~PAGE_MASK)));
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)table)), PAGE_SIZE * 2, "DMI Decoder Finding Table", Region::Access::Read, false, false);
|
||||
SMBIOS::TableHeader* table_v_ptr = (SMBIOS::TableHeader*)region->vaddr().offset(offset_in_page((u32)table)).as_ptr();
|
||||
|
||||
if (table_v_ptr->handle == handle) {
|
||||
return table;
|
||||
}
|
||||
|
@ -138,14 +140,12 @@ SMBIOS::TableHeader* DMIDecoder::get_smbios_physical_table_by_handle(u16 handle)
|
|||
}
|
||||
SMBIOS::TableHeader* DMIDecoder::get_smbios_physical_table_by_type(u8 table_type)
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(PAGE_ROUND_UP(PAGE_SIZE * 2), "DMI Decoder Finding Table", Region::Access::Read);
|
||||
|
||||
for (auto* table : m_smbios_tables) {
|
||||
if (!table)
|
||||
continue;
|
||||
PhysicalAddress paddr = PhysicalAddress((u32)table & PAGE_MASK);
|
||||
mmap_region(*region, paddr);
|
||||
SMBIOS::TableHeader* table_v_ptr = (SMBIOS::TableHeader*)(region->vaddr().get() + ((u32)table & (~PAGE_MASK)));
|
||||
auto region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)table)), PAGE_ROUND_UP(PAGE_SIZE * 2), "DMI Decoder Finding Table", Region::Access::Read, false, false);
|
||||
SMBIOS::TableHeader* table_v_ptr = (SMBIOS::TableHeader*)region->vaddr().offset(offset_in_page((u32)table)).as_ptr();
|
||||
if (table_v_ptr->type == table_type) {
|
||||
return table;
|
||||
}
|
||||
|
@ -167,14 +167,13 @@ DMIDecoder::DMIDecoder(bool trusted)
|
|||
|
||||
SMBIOS::EntryPoint64bit* DMIDecoder::find_entry64bit_point()
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(PAGE_ROUND_UP(SMBIOS_SEARCH_AREA_SIZE), "DMI Decoder Entry Point Finding", Region::Access::Read);
|
||||
PhysicalAddress paddr = PhysicalAddress(SMBIOS_BASE_SEARCH_ADDR);
|
||||
mmap_region(*region, paddr);
|
||||
auto region = MM.allocate_kernel_region(paddr, PAGE_ROUND_UP(SMBIOS_SEARCH_AREA_SIZE), "DMI Decoder Entry Point 64 bit Finding", Region::Access::Read, false, false);
|
||||
|
||||
char* tested_physical_ptr = (char*)paddr.get();
|
||||
for (char* entry_str = (char*)(region->vaddr().get()); entry_str < (char*)(region->vaddr().get() + (SMBIOS_SEARCH_AREA_SIZE)); entry_str += 16) {
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMI Decoder: Looking for 64 bit Entry point @ P 0x%x\n", entry_str, tested_physical_ptr);
|
||||
dbgprintf("DMI Decoder: Looking for 64 bit Entry point @ V 0x%x P 0x%x\n", entry_str, tested_physical_ptr);
|
||||
#endif
|
||||
if (!strncmp("_SM3_", entry_str, strlen("_SM3_")))
|
||||
return (SMBIOS::EntryPoint64bit*)tested_physical_ptr;
|
||||
|
@ -186,14 +185,13 @@ SMBIOS::EntryPoint64bit* DMIDecoder::find_entry64bit_point()
|
|||
|
||||
SMBIOS::EntryPoint32bit* DMIDecoder::find_entry32bit_point()
|
||||
{
|
||||
auto region = MM.allocate_kernel_region(PAGE_ROUND_UP(SMBIOS_SEARCH_AREA_SIZE), "DMI Decoder Entry Point Finding", Region::Access::Read);
|
||||
PhysicalAddress paddr = PhysicalAddress(SMBIOS_BASE_SEARCH_ADDR);
|
||||
mmap_region(*region, paddr);
|
||||
auto region = MM.allocate_kernel_region(paddr, PAGE_ROUND_UP(SMBIOS_SEARCH_AREA_SIZE), "DMI Decoder Entry Point 32 bit Finding", Region::Access::Read, false, false);
|
||||
|
||||
char* tested_physical_ptr = (char*)paddr.get();
|
||||
for (char* entry_str = (char*)(region->vaddr().get()); entry_str < (char*)(region->vaddr().get() + (SMBIOS_SEARCH_AREA_SIZE)); entry_str += 16) {
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMI Decoder: Looking for 32 bit Entry point @ P 0x%x\n", tested_physical_ptr);
|
||||
dbgprintf("DMI Decoder: Looking for 32 bit Entry point @ V 0x%x P 0x%x\n", entry_str, tested_physical_ptr);
|
||||
#endif
|
||||
if (!strncmp("_SM_", entry_str, strlen("_SM_")))
|
||||
return (SMBIOS::EntryPoint32bit*)tested_physical_ptr;
|
||||
|
@ -203,33 +201,6 @@ SMBIOS::EntryPoint32bit* DMIDecoder::find_entry32bit_point()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void DMIDecoder::mmap(VirtualAddress vaddr, PhysicalAddress paddr, u32 length)
|
||||
{
|
||||
unsigned i = 0;
|
||||
while (length >= PAGE_SIZE) {
|
||||
MM.map_for_kernel(VirtualAddress(vaddr.offset(i * PAGE_SIZE).get()), PhysicalAddress(paddr.offset(i * PAGE_SIZE).get()));
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMI Decoder: map - V 0x%x -> P 0x%x\n", vaddr.offset(i * PAGE_SIZE).get(), paddr.offset(i * PAGE_SIZE).get());
|
||||
#endif
|
||||
length -= PAGE_SIZE;
|
||||
i++;
|
||||
}
|
||||
if (length > 0) {
|
||||
MM.map_for_kernel(vaddr.offset(i * PAGE_SIZE), paddr.offset(i * PAGE_SIZE), true);
|
||||
}
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMI Decoder: Finished mapping\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void DMIDecoder::mmap_region(Region& region, PhysicalAddress paddr)
|
||||
{
|
||||
#ifdef SMBIOS_DEBUG
|
||||
dbgprintf("DMI Decoder: Mapping region, size - %u\n", region.size());
|
||||
#endif
|
||||
mmap(region.vaddr(), paddr, region.size());
|
||||
}
|
||||
|
||||
Vector<SMBIOS::PhysicalMemoryArray*>& DMIDecoder::get_physical_memory_areas()
|
||||
{
|
||||
// FIXME: Implement it...
|
||||
|
|
|
@ -1325,9 +1325,6 @@ private:
|
|||
SMBIOS::EntryPoint32bit* find_entry32bit_point();
|
||||
SMBIOS::EntryPoint64bit* find_entry64bit_point();
|
||||
|
||||
void mmap(VirtualAddress vaddr, PhysicalAddress paddr, u32 length);
|
||||
void mmap_region(Region& region, PhysicalAddress paddr);
|
||||
|
||||
SMBIOS::EntryPoint32bit* m_entry32bit_point;
|
||||
SMBIOS::EntryPoint64bit* m_entry64bit_point;
|
||||
SMBIOS::TableHeader* m_structure_table;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <Kernel/VM/PhysicalAddress.h>
|
||||
#include <Kernel/VM/VirtualAddress.h>
|
||||
#include <Kernel/kstdio.h>
|
||||
|
||||
|
@ -421,7 +422,12 @@ struct [[gnu::aligned(16)]] FPUState
|
|||
|
||||
inline constexpr u32 page_base_of(u32 address)
|
||||
{
|
||||
return address & 0xfffff000;
|
||||
return address & PAGE_MASK;
|
||||
}
|
||||
|
||||
inline constexpr u32 offset_in_page(u32 address)
|
||||
{
|
||||
return address & (~PAGE_MASK);
|
||||
}
|
||||
|
||||
class CPUID {
|
||||
|
|
|
@ -135,7 +135,7 @@ void disable_bus_mastering(Address address)
|
|||
{
|
||||
PCI::Access::the().disable_bus_mastering(address);
|
||||
}
|
||||
u32 get_BAR_Space_Size(Address address, u8 bar_number)
|
||||
size_t get_BAR_Space_Size(Address address, u8 bar_number)
|
||||
{
|
||||
return PCI::Access::the().get_BAR_Space_Size(address, bar_number);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
virtual u32 get_BAR4(Address address) { return read32_field(address, PCI_BAR4); }
|
||||
virtual u32 get_BAR5(Address address) { return read32_field(address, PCI_BAR5); }
|
||||
|
||||
virtual u32 get_BAR_Space_Size(Address address, u8 bar_number)
|
||||
virtual size_t get_BAR_Space_Size(Address address, u8 bar_number)
|
||||
{
|
||||
// See PCI Spec 2.3, Page 222
|
||||
ASSERT(bar_number < 6);
|
||||
|
|
|
@ -135,7 +135,7 @@ u8 get_subclass(Address);
|
|||
u8 get_class(Address);
|
||||
u16 get_subsystem_id(Address);
|
||||
u16 get_subsystem_vendor_id(Address);
|
||||
u32 get_BAR_Space_Size(Address, u8);
|
||||
size_t get_BAR_Space_Size(Address, u8);
|
||||
void enable_bus_mastering(Address);
|
||||
void disable_bus_mastering(Address);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue