mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Kernel: Simplify PCI::MMIOAccess segment storage
Instead of nesting a bunch of heap allocations, just store them in a simple HashMap<u16, MMIOSegment>. Also fix a bunch of double hash lookups like this: ASSERT(map.contains(key)); auto thing = map.get(key).value(); They now look like this instead: auto thing = map.get(key); ASSERT(thing.has_value());
This commit is contained in:
parent
0de368e36c
commit
c8b309a3b5
Notes:
sideshowbarker
2024-07-19 07:48:02 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c8b309a3b58
@ -55,14 +55,16 @@ uint32_t MMIOAccess::segment_count() const
|
|||||||
|
|
||||||
uint8_t MMIOAccess::segment_start_bus(u32 seg) const
|
uint8_t MMIOAccess::segment_start_bus(u32 seg) const
|
||||||
{
|
{
|
||||||
ASSERT(m_segments.contains(seg));
|
auto segment = m_segments.get(seg);
|
||||||
return m_segments.get(seg).value()->get_start_bus();
|
ASSERT(segment.has_value());
|
||||||
|
return segment.value().get_start_bus();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MMIOAccess::segment_end_bus(u32 seg) const
|
uint8_t MMIOAccess::segment_end_bus(u32 seg) const
|
||||||
{
|
{
|
||||||
ASSERT(m_segments.contains(seg));
|
auto segment = m_segments.get(seg);
|
||||||
return m_segments.get(seg).value()->get_end_bus();
|
ASSERT(segment.has_value());
|
||||||
|
return segment.value().get_end_bus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMIOAccess::initialize(PhysicalAddress mcfg)
|
void MMIOAccess::initialize(PhysicalAddress mcfg)
|
||||||
@ -73,7 +75,6 @@ void MMIOAccess::initialize(PhysicalAddress mcfg)
|
|||||||
|
|
||||||
MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
||||||
: m_mcfg(p_mcfg)
|
: m_mcfg(p_mcfg)
|
||||||
, m_segments(*new HashMap<u16, MMIOSegment*>())
|
|
||||||
, m_mapped_address(ChangeableAddress(0xFFFF, 0xFF, 0xFF, 0xFF))
|
, m_mapped_address(ChangeableAddress(0xFFFF, 0xFF, 0xFF, 0xFF))
|
||||||
{
|
{
|
||||||
klog() << "PCI: Using MMIO Mechanism for PCI Configuartion Space Access";
|
klog() << "PCI: Using MMIO Mechanism for PCI Configuartion Space Access";
|
||||||
@ -103,7 +104,7 @@ MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
|||||||
u8 end_bus = mcfg.descriptors[index].end_pci_bus;
|
u8 end_bus = mcfg.descriptors[index].end_pci_bus;
|
||||||
u32 lower_addr = mcfg.descriptors[index].base_addr;
|
u32 lower_addr = mcfg.descriptors[index].base_addr;
|
||||||
|
|
||||||
m_segments.set(index, new MMIOSegment(PhysicalAddress(lower_addr), start_bus, end_bus));
|
m_segments.set(index, { PhysicalAddress(lower_addr), start_bus, end_bus });
|
||||||
klog() << "PCI: New PCI segment @ " << PhysicalAddress(lower_addr) << ", PCI buses (" << start_bus << "-" << end_bus << ")";
|
klog() << "PCI: New PCI segment @ " << PhysicalAddress(lower_addr) << ", PCI buses (" << start_bus << "-" << end_bus << ")";
|
||||||
}
|
}
|
||||||
mcfg_region->unmap();
|
mcfg_region->unmap();
|
||||||
@ -124,11 +125,11 @@ void MMIOAccess::map_device(Address address)
|
|||||||
return;
|
return;
|
||||||
// FIXME: Map and put some lock!
|
// FIXME: Map and put some lock!
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
ASSERT(m_segments.contains(address.seg()));
|
|
||||||
auto segment = m_segments.get(address.seg());
|
auto segment = m_segments.get(address.seg());
|
||||||
PhysicalAddress segment_lower_addr = segment.value()->get_paddr();
|
ASSERT(segment.has_value());
|
||||||
|
PhysicalAddress segment_lower_addr = segment.value().get_paddr();
|
||||||
PhysicalAddress device_physical_mmio_space = segment_lower_addr.offset(
|
PhysicalAddress device_physical_mmio_space = segment_lower_addr.offset(
|
||||||
PCI_MMIO_CONFIG_SPACE_SIZE * address.function() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE) * address.slot() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE * PCI_MAX_DEVICES_PER_BUS) * (address.bus() - segment.value()->get_start_bus()));
|
PCI_MMIO_CONFIG_SPACE_SIZE * address.function() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE) * address.slot() + (PCI_MMIO_CONFIG_SPACE_SIZE * PCI_MAX_FUNCTIONS_PER_DEVICE * PCI_MAX_DEVICES_PER_BUS) * (address.bus() - segment.value().get_start_bus()));
|
||||||
|
|
||||||
#ifdef PCI_DEBUG
|
#ifdef PCI_DEBUG
|
||||||
dbg() << "PCI: Mapping device @ pci (" << String::format("%w", address.seg()) << ":" << String::format("%b", address.bus()) << ":" << String::format("%b", address.slot()) << "." << String::format("%b", address.function()) << ")"
|
dbg() << "PCI: Mapping device @ pci (" << String::format("%w", address.seg()) << ":" << String::format("%b", address.bus()) << ":" << String::format("%b", address.slot()) << "." << String::format("%b", address.function()) << ")"
|
||||||
|
@ -63,7 +63,7 @@ private:
|
|||||||
virtual u8 segment_end_bus(u32) const override;
|
virtual u8 segment_end_bus(u32) const override;
|
||||||
|
|
||||||
PhysicalAddress m_mcfg;
|
PhysicalAddress m_mcfg;
|
||||||
HashMap<u16, MMIOSegment*>& m_segments;
|
HashMap<u16, MMIOSegment> m_segments;
|
||||||
OwnPtr<Region> m_mmio_window_region;
|
OwnPtr<Region> m_mmio_window_region;
|
||||||
ChangeableAddress m_mapped_address;
|
ChangeableAddress m_mapped_address;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user