diff options
Diffstat (limited to 'Kernel/Bus/PCI')
-rw-r--r-- | Kernel/Bus/PCI/Initializer.cpp | 2 | ||||
-rw-r--r-- | Kernel/Bus/PCI/SysFSPCI.cpp | 139 | ||||
-rw-r--r-- | Kernel/Bus/PCI/SysFSPCI.h | 56 |
3 files changed, 1 insertions, 196 deletions
diff --git a/Kernel/Bus/PCI/Initializer.cpp b/Kernel/Bus/PCI/Initializer.cpp index 159948484e..fd51bdd488 100644 --- a/Kernel/Bus/PCI/Initializer.cpp +++ b/Kernel/Bus/PCI/Initializer.cpp @@ -8,8 +8,8 @@ #include <Kernel/Bus/PCI/API.h> #include <Kernel/Bus/PCI/Access.h> #include <Kernel/Bus/PCI/Initializer.h> -#include <Kernel/Bus/PCI/SysFSPCI.h> #include <Kernel/CommandLine.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h> #include <Kernel/Firmware/ACPI/Parser.h> #include <Kernel/Panic.h> #include <Kernel/Sections.h> diff --git a/Kernel/Bus/PCI/SysFSPCI.cpp b/Kernel/Bus/PCI/SysFSPCI.cpp deleted file mode 100644 index 069ae33804..0000000000 --- a/Kernel/Bus/PCI/SysFSPCI.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <Kernel/Bus/PCI/API.h> -#include <Kernel/Bus/PCI/Access.h> -#include <Kernel/Bus/PCI/SysFSPCI.h> -#include <Kernel/Debug.h> -#include <Kernel/Sections.h> - -namespace Kernel::PCI { - -UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, Address address) -{ - // FIXME: Handle allocation failure gracefully - auto device_name = MUST(KString::formatted("{:04x}:{:02x}:{:02x}.{}", address.domain(), address.bus(), address.device(), address.function())); - return adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, address)); -} - -UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(NonnullOwnPtr<KString> device_directory_name, SysFSDirectory const& parent_directory, Address address) - : SysFSDirectory(parent_directory) - , m_address(address) - , m_device_directory_name(move(device_directory_name)) -{ - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::VENDOR_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::DEVICE_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::CLASS, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBCLASS, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::REVISION_ID, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::PROG_IF, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBSYSTEM_VENDOR_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBSYSTEM_ID, 2)); - - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR0, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR1, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR2, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR3, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR4, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR5, 4)); -} - -UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize() -{ - auto pci_directory = adopt_ref(*new (nothrow) PCIBusSysFSDirectory()); - SysFSComponentRegistry::the().register_new_bus_directory(pci_directory); -} - -UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory() - : SysFSDirectory(SysFSComponentRegistry::the().buses_directory()) -{ - MUST(PCI::enumerate([&](DeviceIdentifier const& device_identifier) { - auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, device_identifier.address()); - m_components.append(pci_device); - })); -} - -StringView PCIDeviceAttributeSysFSComponent::name() const -{ - switch (m_offset) { - case PCI::RegisterOffset::VENDOR_ID: - return "vendor"sv; - case PCI::RegisterOffset::DEVICE_ID: - return "device_id"sv; - case PCI::RegisterOffset::CLASS: - return "class"sv; - case PCI::RegisterOffset::SUBCLASS: - return "subclass"sv; - case PCI::RegisterOffset::REVISION_ID: - return "revision"sv; - case PCI::RegisterOffset::PROG_IF: - return "progif"sv; - case PCI::RegisterOffset::SUBSYSTEM_VENDOR_ID: - return "subsystem_vendor"sv; - case PCI::RegisterOffset::SUBSYSTEM_ID: - return "subsystem_id"sv; - case PCI::RegisterOffset::BAR0: - return "bar0"sv; - case PCI::RegisterOffset::BAR1: - return "bar1"sv; - case PCI::RegisterOffset::BAR2: - return "bar2"sv; - case PCI::RegisterOffset::BAR3: - return "bar3"sv; - case PCI::RegisterOffset::BAR4: - return "bar4"sv; - case PCI::RegisterOffset::BAR5: - return "bar5"sv; - default: - VERIFY_NOT_REACHED(); - } -} - -NonnullRefPtr<PCIDeviceAttributeSysFSComponent> PCIDeviceAttributeSysFSComponent::create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width) -{ - return adopt_ref(*new (nothrow) PCIDeviceAttributeSysFSComponent(device, offset, field_bytes_width)); -} - -PCIDeviceAttributeSysFSComponent::PCIDeviceAttributeSysFSComponent(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width) - : SysFSComponent() - , m_device(device) - , m_offset(offset) - , m_field_bytes_width(field_bytes_width) -{ -} - -ErrorOr<size_t> PCIDeviceAttributeSysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const -{ - auto blob = TRY(try_to_generate_buffer()); - - if ((size_t)offset >= blob->size()) - return 0; - - ssize_t nread = min(static_cast<off_t>(blob->size() - offset), static_cast<off_t>(count)); - TRY(buffer.write(blob->data() + offset, nread)); - return nread; -} - -ErrorOr<NonnullOwnPtr<KBuffer>> PCIDeviceAttributeSysFSComponent::try_to_generate_buffer() const -{ - OwnPtr<KString> value; - switch (m_field_bytes_width) { - case 1: - value = TRY(KString::formatted("{:#x}", PCI::read8(m_device->address(), m_offset))); - break; - case 2: - value = TRY(KString::formatted("{:#x}", PCI::read16(m_device->address(), m_offset))); - break; - case 4: - value = TRY(KString::formatted("{:#x}", PCI::read32(m_device->address(), m_offset))); - break; - default: - VERIFY_NOT_REACHED(); - } - - return KBuffer::try_create_with_bytes(value->view().bytes()); -} -} diff --git a/Kernel/Bus/PCI/SysFSPCI.h b/Kernel/Bus/PCI/SysFSPCI.h deleted file mode 100644 index 80c09e46e5..0000000000 --- a/Kernel/Bus/PCI/SysFSPCI.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/Vector.h> -#include <Kernel/Bus/PCI/Definitions.h> -#include <Kernel/FileSystem/SysFS.h> - -namespace Kernel::PCI { - -class PCIBusSysFSDirectory final : public SysFSDirectory { -public: - static void initialize(); - virtual StringView name() const override { return "pci"sv; } - -private: - PCIBusSysFSDirectory(); -}; - -class PCIDeviceSysFSDirectory final : public SysFSDirectory { -public: - static NonnullRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, Address); - Address const& address() const { return m_address; } - - virtual StringView name() const override { return m_device_directory_name->view(); } - -private: - PCIDeviceSysFSDirectory(NonnullOwnPtr<KString> device_directory_name, SysFSDirectory const&, Address); - - Address m_address; - - NonnullOwnPtr<KString> m_device_directory_name; -}; - -class PCIDeviceAttributeSysFSComponent : public SysFSComponent { -public: - static NonnullRefPtr<PCIDeviceAttributeSysFSComponent> create(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width); - - virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override; - virtual ~PCIDeviceAttributeSysFSComponent() {}; - - virtual StringView name() const override; - -protected: - ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const; - PCIDeviceAttributeSysFSComponent(PCIDeviceSysFSDirectory const& device, PCI::RegisterOffset offset, size_t field_bytes_width); - NonnullRefPtr<PCIDeviceSysFSDirectory> m_device; - PCI::RegisterOffset m_offset; - size_t m_field_bytes_width; -}; - -} |