RamdiskController.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/OwnPtr.h>
  7. #include <AK/RefPtr.h>
  8. #include <AK/Types.h>
  9. #include <Kernel/Storage/RamdiskController.h>
  10. namespace Kernel {
  11. NonnullRefPtr<RamdiskController> RamdiskController::initialize()
  12. {
  13. return adopt_ref(*new RamdiskController());
  14. }
  15. bool RamdiskController::reset()
  16. {
  17. TODO();
  18. }
  19. bool RamdiskController::shutdown()
  20. {
  21. TODO();
  22. }
  23. size_t RamdiskController::devices_count() const
  24. {
  25. return m_devices.size();
  26. }
  27. void RamdiskController::start_request(const StorageDevice&, AsyncBlockDeviceRequest&)
  28. {
  29. VERIFY_NOT_REACHED();
  30. }
  31. void RamdiskController::complete_current_request(AsyncDeviceRequest::RequestResult)
  32. {
  33. VERIFY_NOT_REACHED();
  34. }
  35. RamdiskController::RamdiskController()
  36. : StorageController()
  37. {
  38. // Populate ramdisk controllers from Multiboot boot modules, if any.
  39. size_t count = 0;
  40. for (auto used_memory_range : MemoryManager::the().used_memory_ranges()) {
  41. if (used_memory_range.type == UsedMemoryRangeType::BootModule) {
  42. size_t length = page_round_up(used_memory_range.end.get()) - used_memory_range.start.get();
  43. auto region = MemoryManager::the().allocate_kernel_region(used_memory_range.start, length, "Ramdisk", Region::Access::Read | Region::Access::Write);
  44. if (!region)
  45. dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length);
  46. else
  47. m_devices.append(RamdiskDevice::create(*this, region.release_nonnull(), 6, count));
  48. count++;
  49. }
  50. }
  51. }
  52. RamdiskController::~RamdiskController()
  53. {
  54. }
  55. RefPtr<StorageDevice> RamdiskController::device(u32 index) const
  56. {
  57. if (index >= m_devices.size())
  58. return nullptr;
  59. return m_devices[index];
  60. }
  61. }