diff options
author | Liav A <liavalb@gmail.com> | 2020-04-10 20:25:03 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-11 10:02:31 +0200 |
commit | 65f939b55c3d2c7c5e9f7f8baf4b748693bf513a (patch) | |
tree | 74b06a5264e68795884805a28f8101ed412007ae /Kernel | |
parent | 688dd9ea66b83fcba6124ddf7d901e227599cfe8 (diff) | |
download | serenity-65f939b55c3d2c7c5e9f7f8baf4b748693bf513a.zip |
Kernel: Keep records of PCI::Address & PCI::ID pairs for enumeration
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Devices/BXVGADevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Devices/PATAChannel.cpp | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 2 | ||||
-rw-r--r-- | Kernel/PCI/Access.cpp | 11 | ||||
-rw-r--r-- | Kernel/PCI/Access.h | 6 | ||||
-rw-r--r-- | Kernel/PCI/Definitions.h | 18 | ||||
-rw-r--r-- | Kernel/PCI/IOAccess.cpp | 5 | ||||
-rw-r--r-- | Kernel/PCI/IOAccess.h | 2 | ||||
-rw-r--r-- | Kernel/PCI/Initializer.cpp | 2 | ||||
-rw-r--r-- | Kernel/PCI/MMIOAccess.cpp | 8 | ||||
-rw-r--r-- | Kernel/PCI/MMIOAccess.h | 2 | ||||
-rw-r--r-- | Kernel/init.cpp | 2 |
12 files changed, 49 insertions, 13 deletions
diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 508f850412..24c878d43b 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -157,7 +157,7 @@ u32 BXVGADevice::find_framebuffer_address() static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 }; static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef }; u32 framebuffer_address = 0; - PCI::enumerate_all([&framebuffer_address](const PCI::Address& address, PCI::ID id) { + PCI::enumerate([&framebuffer_address](const PCI::Address& address, PCI::ID id) { if (id == bochs_vga_id || id == virtualbox_vga_id) { framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0; klog() << "BXVGA: framebuffer @ " << PhysicalAddress(framebuffer_address); diff --git a/Kernel/Devices/PATAChannel.cpp b/Kernel/Devices/PATAChannel.cpp index b7ed53b87f..982ba85b5f 100644 --- a/Kernel/Devices/PATAChannel.cpp +++ b/Kernel/Devices/PATAChannel.cpp @@ -118,7 +118,7 @@ static Lock& s_lock() OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio) { PCI::Address pci_address; - PCI::enumerate_all([&](const PCI::Address& address, PCI::ID id) { + PCI::enumerate([&](const PCI::Address& address, PCI::ID id) { if (PCI::get_class(address) == PCI_Mass_Storage_Class && PCI::get_subclass(address) == PCI_IDE_Controller_Subclass) { pci_address = address; klog() << "PATAChannel: PATA Controller found, ID " << id; diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 2df01329b0..c487b785c2 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -338,7 +338,7 @@ Optional<KBuffer> procfs$pci(InodeIdentifier) { KBufferBuilder builder; JsonArraySerializer array { builder }; - PCI::enumerate_all([&array](PCI::Address address, PCI::ID id) { + PCI::enumerate([&array](PCI::Address address, PCI::ID id) { auto obj = array.add_object(); obj.add("seg", address.seg()); obj.add("bus", address.bus()); diff --git a/Kernel/PCI/Access.cpp b/Kernel/PCI/Access.cpp index 8cd8685cab..999f6b6002 100644 --- a/Kernel/PCI/Access.cpp +++ b/Kernel/PCI/Access.cpp @@ -98,9 +98,16 @@ void Access::enumerate_bus(int type, u8 bus, Function<void(Address, ID)>& callba enumerate_slot(type, bus, slot, callback); } -void enumerate_all(Function<void(Address, ID)> callback) +void Access::enumerate(Function<void(Address, ID)>& callback) const { - Access::the().enumerate_all(callback); + for (auto& physical_id : m_physical_ids) { + callback(physical_id.address(), physical_id.id()); + } +} + +void enumerate(Function<void(Address, ID)> callback) +{ + Access::the().enumerate(callback); } void raw_access(Address address, u32 field, size_t access_size, u32 value) diff --git a/Kernel/PCI/Access.h b/Kernel/PCI/Access.h index 9c4afb3c14..47375f8f4a 100644 --- a/Kernel/PCI/Access.h +++ b/Kernel/PCI/Access.h @@ -27,6 +27,7 @@ #pragma once #include <AK/String.h> +#include <AK/Vector.h> #include <Kernel/PCI/Definitions.h> namespace Kernel { @@ -38,7 +39,7 @@ public: MMIO, }; - virtual void enumerate_all(Function<void(Address, ID)>&) = 0; + void enumerate(Function<void(Address, ID)>&) const; void enumerate_bus(int type, u8 bus, Function<void(Address, ID)>&); void enumerate_functions(int type, u8 bus, u8 slot, u8 function, Function<void(Address, ID)>& callback); @@ -60,7 +61,10 @@ public: virtual u32 read32_field(Address address, u32 field) = 0; protected: + virtual void enumerate_hardware(Function<void(Address, ID)>) = 0; + Access(); + Vector<PhysicalID> m_physical_ids; }; } diff --git a/Kernel/PCI/Definitions.h b/Kernel/PCI/Definitions.h index 634320f298..7c003f331f 100644 --- a/Kernel/PCI/Definitions.h +++ b/Kernel/PCI/Definitions.h @@ -172,8 +172,24 @@ struct ChangeableAddress : public Address { } }; +class PhysicalID { +public: + PhysicalID(Address address, ID id) + : m_address(address) + , m_id(id) + { + } + + const ID& id() const { return m_id; } + const Address& address() const { return m_address; } + +private: + Address m_address; + ID m_id; +}; + ID get_id(PCI::Address); -void enumerate_all(Function<void(Address, ID)> callback); +void enumerate(Function<void(Address, ID)> callback); void enable_interrupt_line(Address); void disable_interrupt_line(Address); u8 get_interrupt_line(Address); diff --git a/Kernel/PCI/IOAccess.cpp b/Kernel/PCI/IOAccess.cpp index 76d58ec9a1..0c6b993bd2 100644 --- a/Kernel/PCI/IOAccess.cpp +++ b/Kernel/PCI/IOAccess.cpp @@ -39,6 +39,9 @@ void IOAccess::initialize() IOAccess::IOAccess() { klog() << "PCI: Using I/O instructions for PCI configuration space access"; + enumerate_hardware([&](const Address& address, ID id) { + m_physical_ids.append({ address, id }); + }); } u8 IOAccess::read8_field(Address address, u32 field) @@ -75,7 +78,7 @@ void IOAccess::write32_field(Address address, u32 field, u32 value) IO::out32(PCI_VALUE_PORT, value); } -void IOAccess::enumerate_all(Function<void(Address, ID)>& callback) +void IOAccess::enumerate_hardware(Function<void(Address, ID)> callback) { // Single PCI host controller. if ((read8_field(Address(), PCI_HEADER_TYPE) & 0x80) == 0) { diff --git a/Kernel/PCI/IOAccess.h b/Kernel/PCI/IOAccess.h index 665d2d6560..57b66da2b6 100644 --- a/Kernel/PCI/IOAccess.h +++ b/Kernel/PCI/IOAccess.h @@ -38,7 +38,7 @@ protected: IOAccess(); private: - virtual void enumerate_all(Function<void(Address, ID)>&) override; + virtual void enumerate_hardware(Function<void(Address, ID)>) override; virtual const char* access_type() const override { return "IO-Access"; }; virtual uint32_t segment_count() const override { return 1; }; virtual void write8_field(Address address, u32, u8) override final; diff --git a/Kernel/PCI/Initializer.cpp b/Kernel/PCI/Initializer.cpp index 9cc60ba232..6ae6575520 100644 --- a/Kernel/PCI/Initializer.cpp +++ b/Kernel/PCI/Initializer.cpp @@ -59,7 +59,7 @@ void initialize() else IOAccess::initialize(); - enumerate_all([&](const Address& address, ID id) { + enumerate([&](const Address& address, ID id) { klog() << address << " " << id; E1000NetworkAdapter::detect(address); RTL8139NetworkAdapter::detect(address); diff --git a/Kernel/PCI/MMIOAccess.cpp b/Kernel/PCI/MMIOAccess.cpp index 6fff1988e7..dfc8f96de7 100644 --- a/Kernel/PCI/MMIOAccess.cpp +++ b/Kernel/PCI/MMIOAccess.cpp @@ -109,7 +109,9 @@ MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg) } mcfg_region->unmap(); klog() << "PCI: MMIO segments - " << m_segments.size(); + InterruptDisabler disabler; + #ifdef PCI_DEBUG dbg() << "PCI: mapped address (" << String::format("%w", m_mapped_address.seg()) << ":" << String::format("%b", m_mapped_address.bus()) << ":" << String::format("%b", m_mapped_address.slot()) << "." << String::format("%b", m_mapped_address.function()) << ")"; #endif @@ -117,6 +119,10 @@ MMIOAccess::MMIOAccess(PhysicalAddress p_mcfg) #ifdef PCI_DEBUG dbg() << "PCI: Default mapped address (" << String::format("%w", m_mapped_address.seg()) << ":" << String::format("%b", m_mapped_address.bus()) << ":" << String::format("%b", m_mapped_address.slot()) << "." << String::format("%b", m_mapped_address.function()) << ")"; #endif + + enumerate_hardware([&](const Address& address, ID id) { + m_physical_ids.append({ address, id }); + }); } void MMIOAccess::map_device(Address address) @@ -204,7 +210,7 @@ void MMIOAccess::write32_field(Address address, u32 field, u32 value) *((u32*)(m_mmio_window_region->vaddr().get() + (field & 0xfff))) = value; } -void MMIOAccess::enumerate_all(Function<void(Address, ID)>& callback) +void MMIOAccess::enumerate_hardware(Function<void(Address, ID)> callback) { for (u16 seg = 0; seg < m_segments.size(); seg++) { #ifdef PCI_DEBUG diff --git a/Kernel/PCI/MMIOAccess.h b/Kernel/PCI/MMIOAccess.h index d61808042b..984dcf31d1 100644 --- a/Kernel/PCI/MMIOAccess.h +++ b/Kernel/PCI/MMIOAccess.h @@ -48,7 +48,7 @@ protected: private: virtual const char* access_type() const override { return "MMIO-Access"; }; virtual u32 segment_count() const override; - virtual void enumerate_all(Function<void(Address, ID)>&) override; + virtual void enumerate_hardware(Function<void(Address, ID)>) override; virtual void write8_field(Address address, u32, u8) override; virtual void write16_field(Address address, u32, u16) override; virtual void write32_field(Address address, u32, u32) override; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index dae4574262..8a5b49046e 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -170,7 +170,7 @@ void init_stage2() dbg() << "Text mode enabled"; } else { bool bxvga_found = false; - PCI::enumerate_all([&](const PCI::Address&, PCI::ID id) { + PCI::enumerate([&](const PCI::Address&, PCI::ID id) { if (id.vendor_id == 0x1234 && id.device_id == 0x1111) bxvga_found = true; }); |