mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:17:44 +00:00
Kernel: Don't use references or pointers to physical addresses
Now the ACPI & PCI code is more safer, because we don't use raw pointers or references to objects or data that are located in the physical address space, so an accidental dereference cannot happen easily. Instead, we use the PhysicalAddress class to represent those addresses.
This commit is contained in:
parent
43d570a1e3
commit
85307dd26e
13 changed files with 91 additions and 102 deletions
|
@ -44,7 +44,7 @@ PCI::Initializer& PCI::Initializer::the()
|
|||
}
|
||||
return *s_pci_initializer;
|
||||
}
|
||||
void PCI::Initializer::initialize_pci_mmio_access(ACPI_RAW::MCFG& mcfg)
|
||||
void PCI::Initializer::initialize_pci_mmio_access(PhysicalAddress mcfg)
|
||||
{
|
||||
PCI::MMIOAccess::initialize(mcfg);
|
||||
detect_devices();
|
||||
|
@ -129,15 +129,12 @@ bool PCI::Initializer::test_pci_io()
|
|||
|
||||
bool PCI::Initializer::test_pci_mmio()
|
||||
{
|
||||
if (ACPIParser::the().find_table("MCFG") != nullptr)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return !ACPIParser::the().find_table("MCFG").is_null();
|
||||
}
|
||||
|
||||
void PCI::Initializer::initialize_pci_mmio_access_after_test()
|
||||
{
|
||||
initialize_pci_mmio_access(*(ACPI_RAW::MCFG*)(ACPIParser::the().find_table("MCFG")));
|
||||
initialize_pci_mmio_access(ACPIParser::the().find_table("MCFG"));
|
||||
}
|
||||
|
||||
void PCI::Initializer::dismiss()
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Kernel {
|
|||
class PCI::Initializer {
|
||||
public:
|
||||
static PCI::Initializer& the();
|
||||
void initialize_pci_mmio_access(ACPI_RAW::MCFG& mcfg);
|
||||
void initialize_pci_mmio_access(PhysicalAddress mcfg);
|
||||
void initialize_pci_io_access();
|
||||
void test_and_initialize(bool disable_pci_mmio);
|
||||
static void dismiss();
|
||||
|
|
|
@ -47,35 +47,35 @@ uint8_t PCI::MMIOAccess::get_segment_end_bus(u32 seg)
|
|||
return m_segments.get(seg).value()->get_end_bus();
|
||||
}
|
||||
|
||||
void PCI::MMIOAccess::initialize(ACPI_RAW::MCFG& mcfg)
|
||||
void PCI::MMIOAccess::initialize(PhysicalAddress mcfg)
|
||||
{
|
||||
if (!PCI::Access::is_initialized())
|
||||
new PCI::MMIOAccess(mcfg);
|
||||
}
|
||||
|
||||
PCI::MMIOAccess::MMIOAccess(ACPI_RAW::MCFG& raw_mcfg)
|
||||
: m_mcfg(raw_mcfg)
|
||||
PCI::MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
||||
: m_mcfg(p_mcfg)
|
||||
, m_segments(*new HashMap<u16, MMIOSegment*>())
|
||||
, m_mapped_address(ChangeableAddress(0xFFFF, 0xFF, 0xFF, 0xFF))
|
||||
{
|
||||
kprintf("PCI: Using MMIO Mechanism for PCI Configuartion Space Access\n");
|
||||
m_mmio_window_region = MM.allocate_kernel_region(PAGE_ROUND_UP(PCI_MMIO_CONFIG_SPACE_SIZE), "PCI MMIO", Region::Access::Read | Region::Access::Write);
|
||||
|
||||
auto checkup_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)&raw_mcfg)), (PAGE_SIZE * 2), "PCI MCFG Checkup", Region::Access::Read | Region::Access::Write);
|
||||
auto checkup_region = MM.allocate_kernel_region(p_mcfg.page_base(), (PAGE_SIZE * 2), "PCI MCFG Checkup", Region::Access::Read | Region::Access::Write);
|
||||
#ifdef PCI_DEBUG
|
||||
dbgprintf("PCI: Checking MCFG Table length to choose the correct mapping size\n");
|
||||
#endif
|
||||
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)checkup_region->vaddr().offset(offset_in_page((u32)&raw_mcfg)).as_ptr();
|
||||
ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)checkup_region->vaddr().offset(p_mcfg.offset_in_page().get()).as_ptr();
|
||||
u32 length = sdt->length;
|
||||
u8 revision = sdt->revision;
|
||||
|
||||
kprintf("PCI: MCFG, length - %u, revision %d\n", length, revision);
|
||||
checkup_region->unmap();
|
||||
|
||||
auto mcfg_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of((u32)&raw_mcfg)), PAGE_ROUND_UP(length) + PAGE_SIZE, "PCI Parsing MCFG", Region::Access::Read | Region::Access::Write);
|
||||
auto mcfg_region = MM.allocate_kernel_region(p_mcfg.page_base(), PAGE_ROUND_UP(length) + PAGE_SIZE, "PCI Parsing MCFG", Region::Access::Read | Region::Access::Write);
|
||||
|
||||
auto& mcfg = *(ACPI_RAW::MCFG*)mcfg_region->vaddr().offset(offset_in_page((u32)&raw_mcfg)).as_ptr();
|
||||
auto& mcfg = *(ACPI_RAW::MCFG*)mcfg_region->vaddr().offset(p_mcfg.offset_in_page().get()).as_ptr();
|
||||
#ifdef PCI_DEBUG
|
||||
dbgprintf("PCI: Checking MCFG @ V 0x%x, P 0x%x\n", &mcfg, &raw_mcfg);
|
||||
#endif
|
||||
|
|
|
@ -39,14 +39,14 @@ namespace Kernel {
|
|||
|
||||
class PCI::MMIOAccess final : public PCI::Access {
|
||||
public:
|
||||
static void initialize(ACPI_RAW::MCFG&);
|
||||
static void initialize(PhysicalAddress mcfg);
|
||||
virtual void enumerate_all(Function<void(Address, ID)>&) override final;
|
||||
|
||||
virtual String get_access_type() override final { return "MMIO-Access"; };
|
||||
virtual u32 get_segments_count();
|
||||
|
||||
protected:
|
||||
explicit MMIOAccess(ACPI_RAW::MCFG&);
|
||||
explicit MMIOAccess(PhysicalAddress mcfg);
|
||||
|
||||
private:
|
||||
virtual u8 read8_field(Address address, u32) override final;
|
||||
|
@ -60,7 +60,7 @@ private:
|
|||
virtual u8 get_segment_start_bus(u32);
|
||||
virtual u8 get_segment_end_bus(u32);
|
||||
|
||||
ACPI_RAW::MCFG& m_mcfg;
|
||||
PhysicalAddress m_mcfg;
|
||||
HashMap<u16, MMIOSegment*>& m_segments;
|
||||
OwnPtr<Region> m_mmio_window_region;
|
||||
PCI::ChangeableAddress m_mapped_address;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue