From d550b098710352553a7801999cbaf912b19ab2cc Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 9 Jun 2023 21:22:30 +0300 Subject: [PATCH] Kernel: Move PC BIOS-related code to the x86_64 architecture directory All code that is related to PC BIOS should not be in the Kernel/Firmware directory as this directory is for abstracted and platform-agnostic code like ACPI (and device tree parsing in the future). This fixes a problem with the aarch64 architecure, as these machines don't have any PC-BIOS in them so actually trying to access these memory locations (EBDA, BIOS ROM) does not make any sense, as they're specific to x86 machines only. --- .../x86_64/Firmware/ACPI/StaticParsing.cpp | 2 +- .../x86_64/Firmware/MultiProcessor/Parser.cpp | 2 +- .../x86_64/Firmware/PCBIOS}/DMI/Definitions.h | 0 .../x86_64/Firmware/PCBIOS/Mapper.cpp} | 2 +- .../x86_64/Firmware/PCBIOS/Mapper.h} | 0 .../Firmware/PCBIOS/SysFSComponent.cpp} | 18 ++++----- .../x86_64/Firmware/PCBIOS/SysFSComponent.h} | 6 +-- .../Firmware/PCBIOS/SysFSDirectory.cpp} | 40 +++++++++---------- .../x86_64/Firmware/PCBIOS/SysFSDirectory.h} | 6 +-- Kernel/CMakeLists.txt | 6 +-- .../SysFS/Subsystems/Firmware/Directory.cpp | 9 ++++- Kernel/Firmware/ACPI/Parser.cpp | 2 +- 12 files changed, 49 insertions(+), 44 deletions(-) rename Kernel/{FileSystem/SysFS/Subsystems/Firmware/BIOS => Arch/x86_64/Firmware/PCBIOS}/DMI/Definitions.h (100%) rename Kernel/{Firmware/BIOS.cpp => Arch/x86_64/Firmware/PCBIOS/Mapper.cpp} (96%) rename Kernel/{Firmware/BIOS.h => Arch/x86_64/Firmware/PCBIOS/Mapper.h} (100%) rename Kernel/{FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp => Arch/x86_64/Firmware/PCBIOS/SysFSComponent.cpp} (54%) rename Kernel/{FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.h => Arch/x86_64/Firmware/PCBIOS/SysFSComponent.h} (80%) rename Kernel/{FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp => Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.cpp} (68%) rename Kernel/{FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h => Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.h} (85%) diff --git a/Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp b/Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp index 3ae2a4866b4..0f8d0aff727 100644 --- a/Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp +++ b/Kernel/Arch/x86_64/Firmware/ACPI/StaticParsing.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include #include namespace Kernel::ACPI::StaticParsing { diff --git a/Kernel/Arch/x86_64/Firmware/MultiProcessor/Parser.cpp b/Kernel/Arch/x86_64/Firmware/MultiProcessor/Parser.cpp index e6cad52e624..0e992bee092 100644 --- a/Kernel/Arch/x86_64/Firmware/MultiProcessor/Parser.cpp +++ b/Kernel/Arch/x86_64/Firmware/MultiProcessor/Parser.cpp @@ -8,9 +8,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/DMI/Definitions.h b/Kernel/Arch/x86_64/Firmware/PCBIOS/DMI/Definitions.h similarity index 100% rename from Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/DMI/Definitions.h rename to Kernel/Arch/x86_64/Firmware/PCBIOS/DMI/Definitions.h diff --git a/Kernel/Firmware/BIOS.cpp b/Kernel/Arch/x86_64/Firmware/PCBIOS/Mapper.cpp similarity index 96% rename from Kernel/Firmware/BIOS.cpp rename to Kernel/Arch/x86_64/Firmware/PCBIOS/Mapper.cpp index 0a1ee1be640..de37889b3b6 100644 --- a/Kernel/Firmware/BIOS.cpp +++ b/Kernel/Arch/x86_64/Firmware/PCBIOS/Mapper.cpp @@ -5,7 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include diff --git a/Kernel/Firmware/BIOS.h b/Kernel/Arch/x86_64/Firmware/PCBIOS/Mapper.h similarity index 100% rename from Kernel/Firmware/BIOS.h rename to Kernel/Arch/x86_64/Firmware/PCBIOS/Mapper.h diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.cpp similarity index 54% rename from Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp rename to Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.cpp index e55a4a1fb90..66f4ed131e6 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp +++ b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.cpp @@ -5,9 +5,9 @@ */ #include +#include +#include #include -#include -#include #include #include #include @@ -15,12 +15,12 @@ namespace Kernel { -NonnullRefPtr BIOSSysFSComponent::must_create(Type type, PhysicalAddress blob_paddr, size_t blob_size) +NonnullRefPtr SysFSPCBIOSComponent::must_create(Type type, PhysicalAddress blob_paddr, size_t blob_size) { - return adopt_ref_if_nonnull(new (nothrow) BIOSSysFSComponent(type, blob_paddr, blob_size)).release_nonnull(); + return adopt_ref_if_nonnull(new (nothrow) SysFSPCBIOSComponent(type, blob_paddr, blob_size)).release_nonnull(); } -UNMAP_AFTER_INIT BIOSSysFSComponent::BIOSSysFSComponent(Type type, PhysicalAddress blob_paddr, size_t blob_size) +UNMAP_AFTER_INIT SysFSPCBIOSComponent::SysFSPCBIOSComponent(Type type, PhysicalAddress blob_paddr, size_t blob_size) : SysFSComponent() , m_blob_paddr(blob_paddr) , m_blob_length(blob_size) @@ -28,7 +28,7 @@ UNMAP_AFTER_INIT BIOSSysFSComponent::BIOSSysFSComponent(Type type, PhysicalAddre { } -ErrorOr BIOSSysFSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const +ErrorOr SysFSPCBIOSComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const { auto blob = TRY(try_to_generate_buffer()); @@ -40,7 +40,7 @@ ErrorOr BIOSSysFSComponent::read_bytes(off_t offset, size_t count, UserO return nread; } -StringView BIOSSysFSComponent::name() const +StringView SysFSPCBIOSComponent::name() const { switch (m_type) { case Type::DMIEntryPoint: @@ -53,9 +53,9 @@ StringView BIOSSysFSComponent::name() const VERIFY_NOT_REACHED(); } -ErrorOr> BIOSSysFSComponent::try_to_generate_buffer() const +ErrorOr> SysFSPCBIOSComponent::try_to_generate_buffer() const { auto blob = TRY(Memory::map_typed((m_blob_paddr), m_blob_length)); - return KBuffer::try_create_with_bytes("BIOSSysFSComponent: Blob"sv, Span { blob.ptr(), m_blob_length }); + return KBuffer::try_create_with_bytes("SysFSPCBIOSComponent: Blob"sv, Span { blob.ptr(), m_blob_length }); } } diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.h b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.h similarity index 80% rename from Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.h rename to Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.h index 8100bb38482..2f287824c21 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.h +++ b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSComponent.h @@ -16,7 +16,7 @@ namespace Kernel { -class BIOSSysFSComponent final : public SysFSComponent { +class SysFSPCBIOSComponent final : public SysFSComponent { public: enum class Type { DMIEntryPoint, @@ -24,13 +24,13 @@ public: }; public: - static NonnullRefPtr must_create(Type, PhysicalAddress, size_t blob_size); + static NonnullRefPtr must_create(Type, PhysicalAddress, size_t blob_size); virtual StringView name() const override; virtual ErrorOr read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override; private: ErrorOr> try_to_generate_buffer() const; - BIOSSysFSComponent(Type, PhysicalAddress, size_t blob_size); + SysFSPCBIOSComponent(Type, PhysicalAddress, size_t blob_size); virtual size_t size() const override { return m_blob_length; } diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.cpp similarity index 68% rename from Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp rename to Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.cpp index 7c6007c9896..d661ce30146 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp +++ b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.cpp @@ -5,11 +5,11 @@ */ #include +#include +#include +#include +#include #include -#include -#include -#include -#include #include #include #include @@ -21,51 +21,51 @@ namespace Kernel { #define SMBIOS_END_SEARCH_ADDR 0xfffff #define SMBIOS_SEARCH_AREA_SIZE (SMBIOS_END_SEARCH_ADDR - SMBIOS_BASE_SEARCH_ADDR) -UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_64_bit_entry_initialization_values() +UNMAP_AFTER_INIT void SysFSBIOSDirectory::set_dmi_64_bit_entry_initialization_values() { - dbgln("BIOSSysFSDirectory: SMBIOS 64bit Entry point @ {}", m_dmi_entry_point); + dbgln("SysFSBIOSDirectory: SMBIOS 64bit Entry point @ {}", m_dmi_entry_point); auto smbios_entry = Memory::map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE).release_value_but_fixme_should_propagate_errors(); m_smbios_structure_table = PhysicalAddress(smbios_entry.ptr()->table_ptr); m_dmi_entry_point_length = smbios_entry.ptr()->length; m_smbios_structure_table_length = smbios_entry.ptr()->table_maximum_size; } -UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_32_bit_entry_initialization_values() +UNMAP_AFTER_INIT void SysFSBIOSDirectory::set_dmi_32_bit_entry_initialization_values() { - dbgln("BIOSSysFSDirectory: SMBIOS 32bit Entry point @ {}", m_dmi_entry_point); + dbgln("SysFSBIOSDirectory: SMBIOS 32bit Entry point @ {}", m_dmi_entry_point); auto smbios_entry = Memory::map_typed(m_dmi_entry_point, SMBIOS_SEARCH_AREA_SIZE).release_value_but_fixme_should_propagate_errors(); m_smbios_structure_table = PhysicalAddress(smbios_entry.ptr()->legacy_structure.smbios_table_ptr); m_dmi_entry_point_length = smbios_entry.ptr()->length; m_smbios_structure_table_length = smbios_entry.ptr()->legacy_structure.smbios_table_length; } -UNMAP_AFTER_INIT NonnullRefPtr BIOSSysFSDirectory::must_create(SysFSFirmwareDirectory& firmware_directory) +UNMAP_AFTER_INIT NonnullRefPtr SysFSBIOSDirectory::must_create(SysFSFirmwareDirectory& firmware_directory) { - auto bios_directory = MUST(adopt_nonnull_ref_or_enomem(new (nothrow) BIOSSysFSDirectory(firmware_directory))); + auto bios_directory = MUST(adopt_nonnull_ref_or_enomem(new (nothrow) SysFSBIOSDirectory(firmware_directory))); bios_directory->create_components(); return bios_directory; } -void BIOSSysFSDirectory::create_components() +void SysFSBIOSDirectory::create_components() { if (m_dmi_entry_point.is_null() || m_smbios_structure_table.is_null()) return; if (m_dmi_entry_point_length == 0) { - dbgln("BIOSSysFSDirectory: invalid dmi entry length"); + dbgln("SysFSBIOSDirectory: invalid dmi entry length"); return; } if (m_smbios_structure_table_length == 0) { - dbgln("BIOSSysFSDirectory: invalid smbios structure table length"); + dbgln("SysFSBIOSDirectory: invalid smbios structure table length"); return; } MUST(m_child_components.with([&](auto& list) -> ErrorOr { - list.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::DMIEntryPoint, m_dmi_entry_point, m_dmi_entry_point_length)); - list.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::SMBIOSTable, m_smbios_structure_table, m_smbios_structure_table_length)); + list.append(SysFSPCBIOSComponent::must_create(SysFSPCBIOSComponent::Type::DMIEntryPoint, m_dmi_entry_point, m_dmi_entry_point_length)); + list.append(SysFSPCBIOSComponent::must_create(SysFSPCBIOSComponent::Type::SMBIOSTable, m_smbios_structure_table, m_smbios_structure_table_length)); return {}; })); } -UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer() +UNMAP_AFTER_INIT void SysFSBIOSDirectory::initialize_dmi_exposer() { VERIFY(!(m_dmi_entry_point.is_null())); if (m_using_64bit_dmi_entry_point) { @@ -73,10 +73,10 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer() } else { set_dmi_32_bit_entry_initialization_values(); } - dbgln("BIOSSysFSDirectory: Data table @ {}", m_smbios_structure_table); + dbgln("SysFSBIOSDirectory: Data table @ {}", m_smbios_structure_table); } -UNMAP_AFTER_INIT BIOSSysFSDirectory::BIOSSysFSDirectory(SysFSFirmwareDirectory& firmware_directory) +UNMAP_AFTER_INIT SysFSBIOSDirectory::SysFSBIOSDirectory(SysFSFirmwareDirectory& firmware_directory) : SysFSDirectory(firmware_directory) { auto entry_32bit = find_dmi_entry32bit_point(); @@ -94,7 +94,7 @@ UNMAP_AFTER_INIT BIOSSysFSDirectory::BIOSSysFSDirectory(SysFSFirmwareDirectory& initialize_dmi_exposer(); } -UNMAP_AFTER_INIT Optional BIOSSysFSDirectory::find_dmi_entry64bit_point() +UNMAP_AFTER_INIT Optional SysFSBIOSDirectory::find_dmi_entry64bit_point() { auto bios_or_error = map_bios(); if (bios_or_error.is_error()) @@ -102,7 +102,7 @@ UNMAP_AFTER_INIT Optional BIOSSysFSDirectory::find_dmi_entry64b return bios_or_error.value().find_chunk_starting_with("_SM3_"sv, 16); } -UNMAP_AFTER_INIT Optional BIOSSysFSDirectory::find_dmi_entry32bit_point() +UNMAP_AFTER_INIT Optional SysFSBIOSDirectory::find_dmi_entry32bit_point() { auto bios_or_error = map_bios(); if (bios_or_error.is_error()) diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.h similarity index 85% rename from Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h rename to Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.h index aa9a4beb83d..a401ca34bdd 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h +++ b/Kernel/Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.h @@ -15,15 +15,15 @@ namespace Kernel { -class BIOSSysFSDirectory : public SysFSDirectory { +class SysFSBIOSDirectory : public SysFSDirectory { public: virtual StringView name() const override { return "bios"sv; } - static NonnullRefPtr must_create(SysFSFirmwareDirectory&); + static NonnullRefPtr must_create(SysFSFirmwareDirectory&); void create_components(); private: - explicit BIOSSysFSDirectory(SysFSFirmwareDirectory&); + explicit SysFSBIOSDirectory(SysFSFirmwareDirectory&); void set_dmi_64_bit_entry_initialization_values(); void set_dmi_32_bit_entry_initialization_values(); diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index c79bf635f83..3dba00ce696 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -172,8 +172,6 @@ set(KERNEL_SOURCES FileSystem/SysFS/Subsystems/Devices/Graphics/DisplayConnector/DeviceDirectory.cpp FileSystem/SysFS/Subsystems/Devices/Graphics/DisplayConnector/DeviceAttribute.cpp FileSystem/SysFS/Subsystems/Devices/Directory.cpp - FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp - FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp FileSystem/SysFS/Subsystems/Firmware/Directory.cpp FileSystem/SysFS/Subsystems/Kernel/Interrupts.cpp FileSystem/SysFS/Subsystems/Kernel/Processes.cpp @@ -206,7 +204,6 @@ set(KERNEL_SOURCES FileSystem/SysFS/Subsystems/Kernel/Variables/StringVariable.cpp FileSystem/SysFS/Subsystems/Kernel/Variables/UBSANDeadly.cpp FileSystem/VirtualFileSystem.cpp - Firmware/BIOS.cpp Firmware/ACPI/Initialize.cpp Firmware/ACPI/Parser.cpp Firmware/ACPI/StaticParsing.cpp @@ -372,6 +369,9 @@ if ("${SERENITY_ARCH}" STREQUAL "x86_64") Arch/x86_64/Firmware/ACPI/StaticParsing.cpp Arch/x86_64/Firmware/MultiProcessor/Parser.cpp + Arch/x86_64/Firmware/PCBIOS/Mapper.cpp + Arch/x86_64/Firmware/PCBIOS/SysFSComponent.cpp + Arch/x86_64/Firmware/PCBIOS/SysFSDirectory.cpp Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp Arch/x86_64/Hypervisor/VMWareBackdoor.cpp diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp index 345c114873f..904ec88e585 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp @@ -4,8 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#if ARCH(X86_64) +# include +#endif #include -#include #include #include #include @@ -22,7 +25,9 @@ UNMAP_AFTER_INIT void SysFSFirmwareDirectory::initialize() void SysFSFirmwareDirectory::create_components() { MUST(m_child_components.with([&](auto& list) -> ErrorOr { - list.append(BIOSSysFSDirectory::must_create(*this)); +#if ARCH(X86_64) + list.append(SysFSBIOSDirectory::must_create(*this)); +#endif if (ACPI::is_enabled()) list.append(ACPI::ACPISysFSDirectory::must_create(*this)); return {}; diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index d69c41e0243..8f65b93da13 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -12,12 +12,12 @@ #include #include #if ARCH(X86_64) +# include # include #endif #include #include #include -#include #include #include #include