mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:42:43 +00:00 
			
		
		
		
	Revert "Revert "Kernel/Storage: Remove the ramdisk implementation""
This reverts commit 187723776a.
This was reverted because it was needed until the aarch64 port
got an SD card driver
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
			
			
This commit is contained in:
		
							parent
							
								
									d09852642c
								
							
						
					
					
						commit
						36c5afdfb2
					
				
					 9 changed files with 0 additions and 232 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
|  | @ -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]; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | @ -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; | ||||
| }; | ||||
| } | ||||
|  | @ -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); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | @ -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; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -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: | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marco Cutecchia
						Marco Cutecchia