|
@@ -24,6 +24,7 @@
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+#include <AK/Debug.h>
|
|
#include <AK/Optional.h>
|
|
#include <AK/Optional.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/StringView.h>
|
|
#include <Kernel/PCI/MMIOAccess.h>
|
|
#include <Kernel/PCI/MMIOAccess.h>
|
|
@@ -110,9 +111,7 @@ MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
|
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_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::Structures::MCFG*)mcfg_region->vaddr().offset(p_mcfg.offset_in_page()).as_ptr();
|
|
auto& mcfg = *(ACPI::Structures::MCFG*)mcfg_region->vaddr().offset(p_mcfg.offset_in_page()).as_ptr();
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: Checking MCFG @ V " << &mcfg << ", P 0x" << String::format("%x", p_mcfg.get());
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: Checking MCFG @ {}, {}", VirtualAddress(&mcfg), PhysicalAddress(p_mcfg.get()));
|
|
|
|
|
|
for (u32 index = 0; index < ((mcfg.header.length - sizeof(ACPI::Structures::MCFG)) / sizeof(ACPI::Structures::PCI_MMIO_Descriptor)); index++) {
|
|
for (u32 index = 0; index < ((mcfg.header.length - sizeof(ACPI::Structures::MCFG)) / sizeof(ACPI::Structures::PCI_MMIO_Descriptor)); index++) {
|
|
u8 start_bus = mcfg.descriptors[index].start_pci_bus;
|
|
u8 start_bus = mcfg.descriptors[index].start_pci_bus;
|
|
@@ -130,36 +129,26 @@ MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg)
|
|
enumerate_hardware([&](const Address& address, ID id) {
|
|
enumerate_hardware([&](const Address& address, ID id) {
|
|
m_mapped_device_regions.append(make<DeviceConfigurationSpaceMapping>(address, m_segments.get(address.seg()).value()));
|
|
m_mapped_device_regions.append(make<DeviceConfigurationSpaceMapping>(address, m_segments.get(address.seg()).value()));
|
|
m_physical_ids.append({ address, id, get_capabilities(address) });
|
|
m_physical_ids.append({ address, id, get_capabilities(address) });
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: Mapping device @ pci (" << address << ")"
|
|
|
|
- << " " << m_mapped_device_regions.last().vaddr() << " " << m_mapped_device_regions.last().paddr();
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: Mapping device @ pci ({}) {} {}", address, m_mapped_device_regions.last().vaddr(), m_mapped_device_regions.last().paddr());
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
Optional<VirtualAddress> MMIOAccess::get_device_configuration_space(Address address)
|
|
Optional<VirtualAddress> MMIOAccess::get_device_configuration_space(Address address)
|
|
{
|
|
{
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: Getting device configuration space for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: Getting device configuration space for {}", address);
|
|
for (auto& mapping : m_mapped_device_regions) {
|
|
for (auto& mapping : m_mapped_device_regions) {
|
|
auto checked_address = mapping.address();
|
|
auto checked_address = mapping.address();
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI Device Configuration Space Mapping: Check if " << checked_address << " was requested";
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI Device Configuration Space Mapping: Check if {} was requested", checked_address);
|
|
if (address.seg() == checked_address.seg()
|
|
if (address.seg() == checked_address.seg()
|
|
&& address.bus() == checked_address.bus()
|
|
&& address.bus() == checked_address.bus()
|
|
&& address.slot() == checked_address.slot()
|
|
&& address.slot() == checked_address.slot()
|
|
&& address.function() == checked_address.function()) {
|
|
&& address.function() == checked_address.function()) {
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI Device Configuration Space Mapping: Found " << checked_address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI Device Configuration Space Mapping: Found {}", checked_address);
|
|
return mapping.vaddr();
|
|
return mapping.vaddr();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: No device configuration space found for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+
|
|
|
|
+ dbgln<debug_pci>("PCI: No device configuration space found for {}", address);
|
|
return {};
|
|
return {};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -167,9 +156,7 @@ u8 MMIOAccess::read8_field(Address address, u32 field)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field <= 0xfff);
|
|
ASSERT(field <= 0xfff);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Reading 8-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Reading 8-bit field {:#08x} for {}", field, address);
|
|
return *((u8*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
return *((u8*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -177,9 +164,7 @@ u16 MMIOAccess::read16_field(Address address, u32 field)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field < 0xfff);
|
|
ASSERT(field < 0xfff);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Reading 16-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Reading 16-bit field {:#08x} for {}", field, address);
|
|
return *((u16*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
return *((u16*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -187,9 +172,7 @@ u32 MMIOAccess::read32_field(Address address, u32 field)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field <= 0xffc);
|
|
ASSERT(field <= 0xffc);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Reading 32-bit field 0x" << String::formatted("{:08x}", field) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Reading 32-bit field {:#08x} for {}", field, address);
|
|
return *((u32*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
return *((u32*)(get_device_configuration_space(address).value().get() + (field & 0xfff)));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,36 +180,28 @@ void MMIOAccess::write8_field(Address address, u32 field, u8 value)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field <= 0xfff);
|
|
ASSERT(field <= 0xfff);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Writing to 8-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:02x}", value) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Writing 8-bit field {:#08x}, value={:#02x} for {}", field, value, address);
|
|
*((u8*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
*((u8*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
}
|
|
}
|
|
void MMIOAccess::write16_field(Address address, u32 field, u16 value)
|
|
void MMIOAccess::write16_field(Address address, u32 field, u16 value)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field < 0xfff);
|
|
ASSERT(field < 0xfff);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Writing to 16-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:04x}", value) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Writing 16-bit field {:#08x}, value={:#02x} for {}", field, value, address);
|
|
*((u16*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
*((u16*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
}
|
|
}
|
|
void MMIOAccess::write32_field(Address address, u32 field, u32 value)
|
|
void MMIOAccess::write32_field(Address address, u32 field, u32 value)
|
|
{
|
|
{
|
|
InterruptDisabler disabler;
|
|
InterruptDisabler disabler;
|
|
ASSERT(field <= 0xffc);
|
|
ASSERT(field <= 0xffc);
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: MMIO Writing to 32-bit field 0x" << String::formatted("{:08x}", field) << ", value=0x" << String::formatted("{:08x}", value) << " for " << address;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: MMIO Writing 32-bit field {:#08x}, value={:#02x} for {}", field, value, address);
|
|
*((u32*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
*((u32*)(get_device_configuration_space(address).value().get() + (field & 0xfff))) = value;
|
|
}
|
|
}
|
|
|
|
|
|
void MMIOAccess::enumerate_hardware(Function<void(Address, ID)> callback)
|
|
void MMIOAccess::enumerate_hardware(Function<void(Address, ID)> callback)
|
|
{
|
|
{
|
|
for (u16 seg = 0; seg < m_segments.size(); seg++) {
|
|
for (u16 seg = 0; seg < m_segments.size(); seg++) {
|
|
-#ifdef PCI_DEBUG
|
|
|
|
- dbg() << "PCI: Enumerating Memory mapped IO segment " << seg;
|
|
|
|
-#endif
|
|
|
|
|
|
+ dbgln<debug_pci>("PCI: Enumerating Memory mapped IO segment {}", seg);
|
|
// Single PCI host controller.
|
|
// Single PCI host controller.
|
|
if ((early_read8_field(Address(seg), PCI_HEADER_TYPE) & 0x80) == 0) {
|
|
if ((early_read8_field(Address(seg), PCI_HEADER_TYPE) & 0x80) == 0) {
|
|
enumerate_bus(-1, 0, callback);
|
|
enumerate_bus(-1, 0, callback);
|