From a6a8f36a83049b9c0691320745255f99611d15c4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Apr 2020 17:29:37 +0200 Subject: [PATCH] Kernel: Use nested Kernel::PCI namespaces more to reduce PCI:: spam --- Kernel/PCI/Access.cpp | 35 +++++++++++++++++------------------ Kernel/PCI/Device.cpp | 12 ++++++++---- Kernel/PCI/IOAccess.cpp | 24 +++++++++++++----------- Kernel/PCI/Initializer.cpp | 36 +++++++++++++++++++----------------- 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/Kernel/PCI/Access.cpp b/Kernel/PCI/Access.cpp index 9b2d7919605..8cd8685cabf 100644 --- a/Kernel/PCI/Access.cpp +++ b/Kernel/PCI/Access.cpp @@ -28,17 +28,18 @@ #include namespace Kernel { +namespace PCI { -static PCI::Access* s_access; +static Access* s_access; -inline void write8(PCI::Address address, u32 field, u8 value) { PCI::Access::the().write8_field(address, field, value); } -inline void write16(PCI::Address address, u32 field, u16 value) { PCI::Access::the().write16_field(address, field, value); } -inline void write32(PCI::Address address, u32 field, u32 value) { PCI::Access::the().write32_field(address, field, value); } -inline u8 read8(PCI::Address address, u32 field) { return PCI::Access::the().read8_field(address, field); } -inline u16 read16(PCI::Address address, u32 field) { return PCI::Access::the().read16_field(address, field); } -inline u32 read32(PCI::Address address, u32 field) { return PCI::Access::the().read32_field(address, field); } +inline void write8(Address address, u32 field, u8 value) { Access::the().write8_field(address, field, value); } +inline void write16(Address address, u32 field, u16 value) { Access::the().write16_field(address, field, value); } +inline void write32(Address address, u32 field, u32 value) { Access::the().write32_field(address, field, value); } +inline u8 read8(Address address, u32 field) { return Access::the().read8_field(address, field); } +inline u16 read16(Address address, u32 field) { return Access::the().read16_field(address, field); } +inline u32 read32(Address address, u32 field) { return Access::the().read32_field(address, field); } -PCI::Access& PCI::Access::the() +Access& Access::the() { if (s_access == nullptr) { ASSERT_NOT_REACHED(); // We failed to initialize the PCI subsystem, so stop here! @@ -46,22 +47,22 @@ PCI::Access& PCI::Access::the() return *s_access; } -bool PCI::Access::is_initialized() +bool Access::is_initialized() { return (s_access != nullptr); } -PCI::Access::Access() +Access::Access() { s_access = this; } -static u16 read_type(PCI::Address address) +static u16 read_type(Address address) { return (read8(address, PCI_CLASS) << 8u) | read8(address, PCI_SUBCLASS); } -void PCI::Access::enumerate_functions(int type, u8 bus, u8 slot, u8 function, Function& callback) +void Access::enumerate_functions(int type, u8 bus, u8 slot, u8 function, Function& callback) { Address address(0, bus, slot, function); if (type == -1 || type == read_type(address)) @@ -76,7 +77,7 @@ void PCI::Access::enumerate_functions(int type, u8 bus, u8 slot, u8 function, Fu } } -void PCI::Access::enumerate_slot(int type, u8 bus, u8 slot, Function& callback) +void Access::enumerate_slot(int type, u8 bus, u8 slot, Function& callback) { Address address(0, bus, slot, 0); if (read16_field(address, PCI_VENDOR_ID) == PCI_NONE) @@ -91,17 +92,15 @@ void PCI::Access::enumerate_slot(int type, u8 bus, u8 slot, Function& callback) +void Access::enumerate_bus(int type, u8 bus, Function& callback) { for (u8 slot = 0; slot < 32; ++slot) enumerate_slot(type, bus, slot, callback); } -namespace PCI { - void enumerate_all(Function callback) { - PCI::Access::the().enumerate_all(callback); + Access::the().enumerate_all(callback); } void raw_access(Address address, u32 field, size_t access_size, u32 value) @@ -226,6 +225,6 @@ size_t get_BAR_space_size(Address address, u8 bar_number) space_size = (~space_size) + 1; return space_size; } -} } +} diff --git a/Kernel/PCI/Device.cpp b/Kernel/PCI/Device.cpp index faa45b3ff78..5300b3dab3f 100644 --- a/Kernel/PCI/Device.cpp +++ b/Kernel/PCI/Device.cpp @@ -27,22 +27,26 @@ #include namespace Kernel { -PCI::Device::Device(PCI::Address address) - : IRQHandler(PCI::get_interrupt_line(address)) +namespace PCI { + +Device::Device(Address address) + : IRQHandler(get_interrupt_line(address)) , m_pci_address(address) { // FIXME: Register PCI device somewhere... } -PCI::Device::Device(PCI::Address address, u8 interrupt_vector) +Device::Device(Address address, u8 interrupt_vector) : IRQHandler(interrupt_vector) , m_pci_address(address) { // FIXME: Register PCI device somewhere... } -PCI::Device::~Device() +Device::~Device() { // FIXME: Unregister the device } + +} } diff --git a/Kernel/PCI/IOAccess.cpp b/Kernel/PCI/IOAccess.cpp index e464952f255..c7947b3ecba 100644 --- a/Kernel/PCI/IOAccess.cpp +++ b/Kernel/PCI/IOAccess.cpp @@ -28,53 +28,54 @@ #include namespace Kernel { +namespace PCI { -void PCI::IOAccess::initialize() +void IOAccess::initialize() { - if (!PCI::Access::is_initialized()) - new PCI::IOAccess(); + if (!Access::is_initialized()) + new IOAccess(); } -PCI::IOAccess::IOAccess() +IOAccess::IOAccess() { klog() << "PCI: Using IO Mechanism for PCI Configuartion Space Access"; } -u8 PCI::IOAccess::read8_field(Address address, u32 field) +u8 IOAccess::read8_field(Address address, u32 field) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); return IO::in8(PCI_VALUE_PORT + (field & 3)); } -u16 PCI::IOAccess::read16_field(Address address, u32 field) +u16 IOAccess::read16_field(Address address, u32 field) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); return IO::in16(PCI_VALUE_PORT + (field & 2)); } -u32 PCI::IOAccess::read32_field(Address address, u32 field) +u32 IOAccess::read32_field(Address address, u32 field) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); return IO::in32(PCI_VALUE_PORT); } -void PCI::IOAccess::write8_field(Address address, u32 field, u8 value) +void IOAccess::write8_field(Address address, u32 field, u8 value) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); IO::out8(PCI_VALUE_PORT + (field & 3), value); } -void PCI::IOAccess::write16_field(Address address, u32 field, u16 value) +void IOAccess::write16_field(Address address, u32 field, u16 value) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); IO::out16(PCI_VALUE_PORT + (field & 2), value); } -void PCI::IOAccess::write32_field(Address address, u32 field, u32 value) +void IOAccess::write32_field(Address address, u32 field, u32 value) { IO::out32(PCI_ADDRESS_PORT, address.io_address_for_field(field)); IO::out32(PCI_VALUE_PORT, value); } -void PCI::IOAccess::enumerate_all(Function& callback) +void IOAccess::enumerate_all(Function& callback) { // Single PCI host controller. if ((read8_field(Address(), PCI_HEADER_TYPE) & 0x80) == 0) { @@ -91,3 +92,4 @@ void PCI::IOAccess::enumerate_all(Function& callback) } } +} diff --git a/Kernel/PCI/Initializer.cpp b/Kernel/PCI/Initializer.cpp index 73e601b8145..f5efeaa65c1 100644 --- a/Kernel/PCI/Initializer.cpp +++ b/Kernel/PCI/Initializer.cpp @@ -34,37 +34,38 @@ #include namespace Kernel { +namespace PCI { -static PCI::Initializer* s_pci_initializer; +static Initializer* s_pci_initializer; -PCI::Initializer& PCI::Initializer::the() +Initializer& Initializer::the() { if (s_pci_initializer == nullptr) { - s_pci_initializer = new PCI::Initializer(); + s_pci_initializer = new Initializer(); } return *s_pci_initializer; } -void PCI::Initializer::initialize_pci_mmio_access(PhysicalAddress mcfg) +void Initializer::initialize_pci_mmio_access(PhysicalAddress mcfg) { - PCI::MMIOAccess::initialize(mcfg); + MMIOAccess::initialize(mcfg); detect_devices(); } -void PCI::Initializer::initialize_pci_io_access() +void Initializer::initialize_pci_io_access() { - PCI::IOAccess::initialize(); + IOAccess::initialize(); detect_devices(); } -void PCI::Initializer::detect_devices() +void Initializer::detect_devices() { - PCI::enumerate_all([&](const PCI::Address& address, PCI::ID id) { + enumerate_all([&](const Address& address, ID id) { klog() << "PCI: device @ " << String::format("%w", address.seg()) << ":" << String::format("%b", address.bus()) << ":" << String::format("%b", address.slot()) << "." << String::format("%d", address.function()) << " [" << String::format("%w", id.vendor_id) << ":" << String::format("%w", id.device_id) << "]"; E1000NetworkAdapter::detect(address); RTL8139NetworkAdapter::detect(address); }); } -void PCI::Initializer::test_and_initialize(bool disable_pci_mmio) +void Initializer::test_and_initialize(bool disable_pci_mmio) { if (disable_pci_mmio) { if (test_pci_io()) { @@ -95,10 +96,10 @@ void PCI::Initializer::test_and_initialize(bool disable_pci_mmio) } } } -PCI::Initializer::Initializer() +Initializer::Initializer() { } -bool PCI::Initializer::test_acpi() +bool Initializer::test_acpi() { if ((kernel_command_line().contains("noacpi")) || !ACPI::Parser::the().is_operable()) return false; @@ -106,7 +107,7 @@ bool PCI::Initializer::test_acpi() return true; } -bool PCI::Initializer::test_pci_io() +bool Initializer::test_pci_io() { klog() << "Testing PCI via manual probing... "; u32 tmp = 0x80000000; @@ -121,17 +122,17 @@ bool PCI::Initializer::test_pci_io() return false; } -bool PCI::Initializer::test_pci_mmio() +bool Initializer::test_pci_mmio() { return !ACPI::Parser::the().find_table("MCFG").is_null(); } -void PCI::Initializer::initialize_pci_mmio_access_after_test() +void Initializer::initialize_pci_mmio_access_after_test() { initialize_pci_mmio_access(ACPI::Parser::the().find_table("MCFG")); } -void PCI::Initializer::dismiss() +void Initializer::dismiss() { if (s_pci_initializer == nullptr) return; @@ -140,8 +141,9 @@ void PCI::Initializer::dismiss() s_pci_initializer = nullptr; } -PCI::Initializer::~Initializer() +Initializer::~Initializer() { } } +}