diff options
author | Liav A <liavalb@gmail.com> | 2022-04-22 10:17:13 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-06-17 11:01:27 +0200 |
commit | 99bac4f34faf8ea3615ef684e7b73c954f12c226 (patch) | |
tree | 2f8798ca7ceb9b4f8db15b24dd53919297ae7797 /Kernel | |
parent | e488245234be2b82127a0131938908b6583c47de (diff) | |
download | serenity-99bac4f34faf8ea3615ef684e7b73c954f12c226.zip |
Kernel/SysFS: Split bulky SysFSPCI file into separate files
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Bus/PCI/Initializer.cpp | 4 | ||||
-rw-r--r-- | Kernel/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp | 31 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h | 23 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.cpp (renamed from Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.cpp) | 48 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.h (renamed from Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h) | 27 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp | 45 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h | 30 |
8 files changed, 138 insertions, 74 deletions
diff --git a/Kernel/Bus/PCI/Initializer.cpp b/Kernel/Bus/PCI/Initializer.cpp index fd51bdd488..2d3de9deac 100644 --- a/Kernel/Bus/PCI/Initializer.cpp +++ b/Kernel/Bus/PCI/Initializer.cpp @@ -9,7 +9,7 @@ #include <Kernel/Bus/PCI/Access.h> #include <Kernel/Bus/PCI/Initializer.h> #include <Kernel/CommandLine.h> -#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h> #include <Kernel/Firmware/ACPI/Parser.h> #include <Kernel/Panic.h> #include <Kernel/Sections.h> @@ -59,7 +59,7 @@ UNMAP_AFTER_INIT void initialize() VERIFY_NOT_REACHED(); } - PCI::PCIBusSysFSDirectory::initialize(); + PCIBusSysFSDirectory::initialize(); MUST(PCI::enumerate([&](DeviceIdentifier const& device_identifier) { dmesgln("{} {}", device_identifier.address(), device_identifier.hardware_id()); diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index b386093a00..be72abbe59 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -143,7 +143,9 @@ set(KERNEL_SOURCES FileSystem/ProcFS.cpp FileSystem/SysFS.cpp FileSystem/SysFS/Component.cpp - FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.cpp + FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp + FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.cpp + FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp FileSystem/SysFS/Subsystems/Bus/USB/DeviceInformation.cpp FileSystem/SysFS/Subsystems/Firmware/BIOS.cpp diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp new file mode 100644 index 0000000000..968c209485 --- /dev/null +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp @@ -0,0 +1,31 @@ +/* + * 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/Debug.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h> +#include <Kernel/Sections.h> + +namespace Kernel { + +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([&](PCI::DeviceIdentifier const& device_identifier) { + auto pci_device = PCIDeviceSysFSDirectory::create(*this, device_identifier.address()); + m_components.append(pci_device); + })); +} + +} diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h new file mode 100644 index 0000000000..5f765a354a --- /dev/null +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <Kernel/Bus/PCI/Definitions.h> +#include <Kernel/FileSystem/SysFS.h> + +namespace Kernel { + +class PCIBusSysFSDirectory final : public SysFSDirectory { +public: + static void initialize(); + virtual StringView name() const override { return "pci"sv; } + +private: + PCIBusSysFSDirectory(); +}; + +} diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.cpp index 90948c5cb8..652dfb5064 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.cpp @@ -7,54 +7,10 @@ #include <Kernel/Bus/PCI/API.h> #include <Kernel/Bus/PCI/Access.h> #include <Kernel/Debug.h> -#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.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); - })); -} +namespace Kernel { StringView PCIDeviceAttributeSysFSComponent::name() const { diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.h index 80c09e46e5..b6e198e80c 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/SysFSPCI.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.h @@ -9,32 +9,9 @@ #include <AK/Vector.h> #include <Kernel/Bus/PCI/Definitions.h> #include <Kernel/FileSystem/SysFS.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.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; -}; +namespace Kernel { class PCIDeviceAttributeSysFSComponent : public SysFSComponent { public: diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp new file mode 100644 index 0000000000..1431e68ac4 --- /dev/null +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp @@ -0,0 +1,45 @@ +/* + * 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/Debug.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceAttribute.h> +#include <Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h> +#include <Kernel/Sections.h> + +namespace Kernel { + +UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(SysFSDirectory const& parent_directory, PCI::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, PCI::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)); +} + +} diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h new file mode 100644 index 0000000000..700b86a170 --- /dev/null +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <Kernel/Bus/PCI/Definitions.h> +#include <Kernel/FileSystem/SysFS.h> +#include <Kernel/KString.h> + +namespace Kernel { + +class PCIDeviceSysFSDirectory final : public SysFSDirectory { +public: + static NonnullRefPtr<PCIDeviceSysFSDirectory> create(SysFSDirectory const&, PCI::Address); + PCI::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&, PCI::Address); + + PCI::Address m_address; + + NonnullOwnPtr<KString> m_device_directory_name; +}; + +} |