diff options
author | Marco Cutecchia <marco.cutecchia@outlook.it> | 2023-03-21 22:08:12 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-25 16:50:36 +0000 |
commit | 36c5afdfb2206a16745ac0ed731ce66a01a5ed02 (patch) | |
tree | f065a296ed4faff589878b0a192d5ee756bbbdc6 | |
parent | d09852642cecbc23ff8faba9b5a810601e7b386a (diff) | |
download | serenity-36c5afdfb2206a16745ac0ed731ce66a01a5ed02.zip |
Revert "Revert "Kernel/Storage: Remove the ramdisk implementation""
This reverts commit 187723776a1140085a187b80effb82f31cc6bb9b.
This was reverted because it was needed until the aarch64 port
got an SD card driver
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
-rw-r--r-- | Kernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Kernel/Storage/Ramdisk/Controller.cpp | 67 | ||||
-rw-r--r-- | Kernel/Storage/Ramdisk/Controller.h | 36 | ||||
-rw-r--r-- | Kernel/Storage/Ramdisk/Device.cpp | 60 | ||||
-rw-r--r-- | Kernel/Storage/Ramdisk/Device.h | 41 | ||||
-rw-r--r-- | Kernel/Storage/StorageDevice.cpp | 2 | ||||
-rw-r--r-- | Kernel/Storage/StorageDevice.h | 1 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.cpp | 22 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.h | 1 |
9 files changed, 0 insertions, 232 deletions
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 09316ae607..f851aaa092 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -108,8 +108,6 @@ set(KERNEL_SOURCES Storage/NVMe/NVMeInterruptQueue.cpp Storage/NVMe/NVMePollQueue.cpp Storage/NVMe/NVMeQueue.cpp - Storage/Ramdisk/Controller.cpp - Storage/Ramdisk/Device.cpp Storage/SD/SDHostController.cpp Storage/SD/SDMemoryCard.cpp Storage/DiskPartition.cpp diff --git a/Kernel/Storage/Ramdisk/Controller.cpp b/Kernel/Storage/Ramdisk/Controller.cpp deleted file mode 100644 index db6b96785f..0000000000 --- a/Kernel/Storage/Ramdisk/Controller.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/OwnPtr.h> -#include <AK/Types.h> -#include <Kernel/Library/LockRefPtr.h> -#include <Kernel/Storage/Ramdisk/Controller.h> - -namespace Kernel { - -ErrorOr<NonnullRefPtr<RamdiskController>> RamdiskController::try_initialize() -{ - return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) RamdiskController())); -} - -ErrorOr<void> RamdiskController::reset() -{ - return Error::from_errno(ENOTIMPL); -} - -ErrorOr<void> RamdiskController::shutdown() -{ - return Error::from_errno(ENOTIMPL); -} - -size_t RamdiskController::devices_count() const -{ - return m_devices.size(); -} - -void RamdiskController::complete_current_request(AsyncDeviceRequest::RequestResult) -{ - VERIFY_NOT_REACHED(); -} - -RamdiskController::RamdiskController() - : StorageController(0) -{ - // Populate ramdisk controllers from Multiboot boot modules, if any. - size_t count = 0; - MM.for_each_used_memory_range([&](auto& used_memory_range) { - if (used_memory_range.type == Memory::UsedMemoryRangeType::BootModule) { - size_t length = Memory::page_round_up(used_memory_range.end.get()).release_value_but_fixme_should_propagate_errors() - used_memory_range.start.get(); - auto region_or_error = MM.allocate_kernel_region(used_memory_range.start, length, "Ramdisk"sv, Memory::Region::Access::ReadWrite); - if (region_or_error.is_error()) { - dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length); - } else { - m_devices.append(RamdiskDevice::create(*this, region_or_error.release_value(), 6, count)); - } - count++; - } - }); -} - -RamdiskController::~RamdiskController() = default; - -LockRefPtr<StorageDevice> RamdiskController::device(u32 index) const -{ - if (index >= m_devices.size()) - return nullptr; - return m_devices[index]; -} - -} diff --git a/Kernel/Storage/Ramdisk/Controller.h b/Kernel/Storage/Ramdisk/Controller.h deleted file mode 100644 index 74d35c5f5b..0000000000 --- a/Kernel/Storage/Ramdisk/Controller.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/OwnPtr.h> -#include <AK/Types.h> -#include <Kernel/Library/LockRefPtr.h> -#include <Kernel/Storage/Ramdisk/Device.h> -#include <Kernel/Storage/StorageController.h> -#include <Kernel/Storage/StorageDevice.h> - -namespace Kernel { - -class AsyncBlockDeviceRequest; - -class RamdiskController final : public StorageController { -public: - static ErrorOr<NonnullRefPtr<RamdiskController>> try_initialize(); - virtual ~RamdiskController() override; - - virtual LockRefPtr<StorageDevice> device(u32 index) const override; - virtual ErrorOr<void> reset() override; - virtual ErrorOr<void> shutdown() override; - virtual size_t devices_count() const override; - virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override; - -private: - RamdiskController(); - - Vector<NonnullLockRefPtr<RamdiskDevice>> m_devices; -}; -} diff --git a/Kernel/Storage/Ramdisk/Device.cpp b/Kernel/Storage/Ramdisk/Device.cpp deleted file mode 100644 index 08033bb0a1..0000000000 --- a/Kernel/Storage/Ramdisk/Device.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2021, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/Memory.h> -#include <AK/StringView.h> -#include <Kernel/Devices/DeviceManagement.h> -#include <Kernel/FileSystem/OpenFileDescription.h> -#include <Kernel/Storage/Ramdisk/Controller.h> -#include <Kernel/Storage/Ramdisk/Device.h> - -namespace Kernel { - -NonnullLockRefPtr<RamdiskDevice> RamdiskDevice::create(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor) -{ - auto device_or_error = DeviceManagement::try_create_device<RamdiskDevice>(controller, move(region), major, minor); - // FIXME: Find a way to propagate errors - VERIFY(!device_or_error.is_error()); - return device_or_error.release_value(); -} - -RamdiskDevice::RamdiskDevice(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor) - : StorageDevice({}, LUNAddress { controller.controller_id(), 0, 0 }, 0, major, minor, 512, region->size() / 512) - , m_region(move(region)) -{ - dmesgln("Ramdisk: Device #{} @ {}, Capacity={}", minor, m_region->vaddr(), max_addressable_block() * 512); -} - -RamdiskDevice::~RamdiskDevice() = default; - -StringView RamdiskDevice::class_name() const -{ - return "RamdiskDevice"sv; -} - -void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request) -{ - MutexLocker locker(m_lock); - - u8* base = m_region->vaddr().as_ptr(); - size_t size = m_region->size(); - u8* offset = base + request.block_index() * request.block_size(); - size_t length = request.buffer_size(); - - if ((offset + length > base + size) || (offset + length < base)) { - request.complete(AsyncDeviceRequest::Failure); - } else { - ErrorOr<void> result; - if (request.request_type() == AsyncBlockDeviceRequest::Read) { - result = request.buffer().write(offset, length); - } else { - result = request.buffer().read(offset, length); - } - request.complete(!result.is_error() ? AsyncDeviceRequest::Success : AsyncDeviceRequest::MemoryFault); - } -} - -} diff --git a/Kernel/Storage/Ramdisk/Device.h b/Kernel/Storage/Ramdisk/Device.h deleted file mode 100644 index 28759bbc9a..0000000000 --- a/Kernel/Storage/Ramdisk/Device.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <Kernel/Locking/Mutex.h> -#include <Kernel/Storage/StorageDevice.h> - -namespace Kernel { - -class RamdiskController; - -class RamdiskDevice final : public StorageDevice { - friend class RamdiskController; - friend class DeviceManagement; - -public: - static NonnullLockRefPtr<RamdiskDevice> create(RamdiskController const&, NonnullOwnPtr<Memory::Region>&& region, int major, int minor); - virtual ~RamdiskDevice() override; - - // ^DiskDevice - virtual StringView class_name() const override; - -private: - RamdiskDevice(RamdiskController const&, NonnullOwnPtr<Memory::Region>&&, int major, int minor); - - // ^BlockDevice - virtual void start_request(AsyncBlockDeviceRequest&) override; - - // ^StorageDevice - virtual CommandSet command_set() const override { return CommandSet::PlainMemory; } - - Mutex m_lock { "RamdiskDevice"sv }; - - NonnullOwnPtr<Memory::Region> m_region; -}; - -} diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp index d61644e2ce..89916fb317 100644 --- a/Kernel/Storage/StorageDevice.cpp +++ b/Kernel/Storage/StorageDevice.cpp @@ -69,8 +69,6 @@ StringView StorageDevice::class_name() const StringView StorageDevice::command_set_to_string_view() const { switch (command_set()) { - case CommandSet::PlainMemory: - return "memory"sv; case CommandSet::SCSI: return "scsi"sv; case CommandSet::ATA: diff --git a/Kernel/Storage/StorageDevice.h b/Kernel/Storage/StorageDevice.h index 736a42dcae..978212f167 100644 --- a/Kernel/Storage/StorageDevice.h +++ b/Kernel/Storage/StorageDevice.h @@ -34,7 +34,6 @@ public: // and ATAPI is the exception to no-distinction rule. If we ever put SCSI support in the kernel, // we can create another enum class to put the distinction. enum class CommandSet { - PlainMemory, SCSI, ATA, NVMe, diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index eccb9d7242..5df9a741ef 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -28,7 +28,6 @@ #include <Kernel/Storage/ATA/AHCI/Controller.h> #include <Kernel/Storage/ATA/GenericIDE/Controller.h> #include <Kernel/Storage/NVMe/NVMeController.h> -#include <Kernel/Storage/Ramdisk/Controller.h> #include <Kernel/Storage/SD/SDHostController.h> #include <Kernel/Storage/StorageManagement.h> #include <LibPartition/EBRPartitionTable.h> @@ -53,7 +52,6 @@ static constexpr StringView block_device_prefix = "block"sv; static constexpr StringView ata_device_prefix = "ata"sv; static constexpr StringView nvme_device_prefix = "nvme"sv; -static constexpr StringView ramdisk_device_prefix = "ramdisk"sv; static constexpr StringView logical_unit_number_device_prefix = "lun"sv; UNMAP_AFTER_INIT StorageManagement::StorageManagement() @@ -304,13 +302,6 @@ UNMAP_AFTER_INIT void StorageManagement::determine_nvme_boot_device() }); } -UNMAP_AFTER_INIT void StorageManagement::determine_ramdisk_boot_device() -{ - determine_hardware_relative_boot_device(ramdisk_device_prefix, [](StorageDevice const& device) -> bool { - return device.command_set() == StorageDevice::CommandSet::PlainMemory; - }); -} - UNMAP_AFTER_INIT void StorageManagement::determine_block_boot_device() { VERIFY(m_boot_argument.starts_with(block_device_prefix)); @@ -370,11 +361,6 @@ UNMAP_AFTER_INIT void StorageManagement::determine_boot_device() return; } - if (m_boot_argument.starts_with(ramdisk_device_prefix)) { - determine_ramdisk_boot_device(); - return; - } - if (m_boot_argument.starts_with(nvme_device_prefix)) { determine_nvme_boot_device(); return; @@ -468,14 +454,6 @@ UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool } #endif - // Note: Whether PCI bus is present on the system or not, always try to attach - // a given ramdisk. - auto controller = RamdiskController::try_initialize(); - if (controller.is_error()) { - dmesgln("Unable to initialize RAM controller: {}", controller.error()); - } else { - m_controllers.append(controller.release_value()); - } enumerate_storage_devices(); enumerate_disk_partitions(); diff --git a/Kernel/Storage/StorageManagement.h b/Kernel/Storage/StorageManagement.h index 1e97eb595c..ef1d22013c 100644 --- a/Kernel/Storage/StorageManagement.h +++ b/Kernel/Storage/StorageManagement.h @@ -53,7 +53,6 @@ private: void resolve_partition_from_boot_device_parameter(StorageDevice const& chosen_storage_device, StringView boot_device_prefix); void determine_boot_device_with_logical_unit_number(); void determine_block_boot_device(); - void determine_ramdisk_boot_device(); void determine_nvme_boot_device(); void determine_ata_boot_device(); void determine_hardware_relative_boot_device(StringView relative_hardware_prefix, Function<bool(StorageDevice const&)> filter_device_callback); |