diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-19 20:53:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-20 17:20:43 +0200 |
commit | 11eee67b8510767d76fb4793e3b62ac1793dd723 (patch) | |
tree | 8ce47a3813ce74bba56c60f62b29bdd6cdf287da /Kernel/Storage/NVMe | |
parent | e475263113387404e63cdc3666391934604eb6e7 (diff) | |
download | serenity-11eee67b8510767d76fb4793e3b62ac1793dd723.zip |
Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:
- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable
This patch renames the Kernel classes so that they can coexist with
the original AK classes:
- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable
The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
Diffstat (limited to 'Kernel/Storage/NVMe')
-rw-r--r-- | Kernel/Storage/NVMe/NVMeController.cpp | 24 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeController.h | 18 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeInterruptQueue.cpp | 2 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeInterruptQueue.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeNameSpace.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeNameSpace.h | 12 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMePollQueue.cpp | 2 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMePollQueue.h | 2 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeQueue.cpp | 10 | ||||
-rw-r--r-- | Kernel/Storage/NVMe/NVMeQueue.h | 18 |
10 files changed, 47 insertions, 47 deletions
diff --git a/Kernel/Storage/NVMe/NVMeController.cpp b/Kernel/Storage/NVMe/NVMeController.cpp index e60731bb44..92cc8b9f65 100644 --- a/Kernel/Storage/NVMe/NVMeController.cpp +++ b/Kernel/Storage/NVMe/NVMeController.cpp @@ -7,7 +7,6 @@ #include "NVMeController.h" #include "AK/Format.h" -#include <AK/RefPtr.h> #include <AK/Types.h> #include <Kernel/Arch/SafeMem.h> #include <Kernel/Arch/x86/IO.h> @@ -16,14 +15,15 @@ #include <Kernel/CommandLine.h> #include <Kernel/Devices/Device.h> #include <Kernel/FileSystem/ProcFS.h> +#include <Kernel/Library/LockRefPtr.h> #include <Kernel/Sections.h> namespace Kernel { Atomic<u8> NVMeController::s_controller_id {}; -UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<NVMeController>> NVMeController::try_initialize(Kernel::PCI::DeviceIdentifier const& device_identifier, bool is_queue_polled) +UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<NVMeController>> NVMeController::try_initialize(Kernel::PCI::DeviceIdentifier const& device_identifier, bool is_queue_polled) { - auto controller = TRY(adopt_nonnull_ref_or_enomem(new NVMeController(device_identifier))); + auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new NVMeController(device_identifier))); TRY(controller->initialize(is_queue_polled)); NVMeController::s_controller_id++; return controller; @@ -49,7 +49,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::initialize(bool is_queue_polled) // Map only until doorbell register for the controller // Queues will individually map the doorbell register respectively - m_controller_regs = TRY(Memory::map_typed_writable<volatile ControllerRegister>(PhysicalAddress(m_bar))); + m_controller_regs = TRY(Memory::map_typed_writable<ControllerRegister volatile>(PhysicalAddress(m_bar))); auto caps = m_controller_regs->cap; m_ready_timeout = Time::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units @@ -152,7 +152,7 @@ UNMAP_AFTER_INIT u32 NVMeController::get_admin_q_dept() UNMAP_AFTER_INIT ErrorOr<void> NVMeController::identify_and_init_namespaces() { - RefPtr<Memory::PhysicalPage> prp_dma_buffer; + LockRefPtr<Memory::PhysicalPage> prp_dma_buffer; OwnPtr<Memory::Region> prp_dma_region; auto namespace_data_struct = TRY(ByteBuffer::create_zeroed(NVMe_IDENTIFY_SIZE)); u32 active_namespace_list[NVMe_IDENTIFY_SIZE / sizeof(u32)]; @@ -225,7 +225,7 @@ UNMAP_AFTER_INIT Tuple<u64, u8> NVMeController::get_ns_features(IdentifyNamespac return Tuple<u64, u8>(namespace_size, lba_size); } -RefPtr<StorageDevice> NVMeController::device(u32 index) const +LockRefPtr<StorageDevice> NVMeController::device(u32 index) const { return m_namespaces.at(index); } @@ -259,9 +259,9 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::create_admin_queue(Optional<u8> i { auto qdepth = get_admin_q_dept(); OwnPtr<Memory::Region> cq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_pages; + NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_pages; OwnPtr<Memory::Region> sq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_pages; + NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_pages; auto cq_size = round_up_to_power_of_two(CQ_SIZE(qdepth), 4096); auto sq_size = round_up_to_power_of_two(SQ_SIZE(qdepth), 4096); if (!reset_controller()) { @@ -281,7 +281,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::create_admin_queue(Optional<u8> i auto buffer = TRY(MM.allocate_dma_buffer_pages(sq_size, "Admin SQ queue"sv, Memory::Region::Access::ReadWrite, sq_dma_pages)); sq_dma_region = move(buffer); } - auto doorbell_regs = TRY(Memory::map_typed_writable<volatile DoorbellRegister>(PhysicalAddress(m_bar + REG_SQ0TDBL_START))); + auto doorbell_regs = TRY(Memory::map_typed_writable<DoorbellRegister volatile>(PhysicalAddress(m_bar + REG_SQ0TDBL_START))); m_controller_regs->acq = reinterpret_cast<u64>(AK::convert_between_host_and_little_endian(cq_dma_pages.first().paddr().as_ptr())); m_controller_regs->asq = reinterpret_cast<u64>(AK::convert_between_host_and_little_endian(sq_dma_pages.first().paddr().as_ptr())); @@ -300,9 +300,9 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::create_admin_queue(Optional<u8> i UNMAP_AFTER_INIT ErrorOr<void> NVMeController::create_io_queue(u8 qid, Optional<u8> irq) { OwnPtr<Memory::Region> cq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_pages; + NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_pages; OwnPtr<Memory::Region> sq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_pages; + NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_pages; auto cq_size = round_up_to_power_of_two(CQ_SIZE(IO_QUEUE_SIZE), 4096); auto sq_size = round_up_to_power_of_two(SQ_SIZE(IO_QUEUE_SIZE), 4096); @@ -349,7 +349,7 @@ UNMAP_AFTER_INIT ErrorOr<void> NVMeController::create_io_queue(u8 qid, Optional< } auto queue_doorbell_offset = REG_SQ0TDBL_START + ((2 * qid) * (4 << m_dbl_stride)); - auto doorbell_regs = TRY(Memory::map_typed_writable<volatile DoorbellRegister>(PhysicalAddress(m_bar + queue_doorbell_offset))); + auto doorbell_regs = TRY(Memory::map_typed_writable<DoorbellRegister volatile>(PhysicalAddress(m_bar + queue_doorbell_offset))); m_queues.append(TRY(NVMeQueue::try_create(qid, irq, IO_QUEUE_SIZE, move(cq_dma_region), cq_dma_pages, move(sq_dma_region), sq_dma_pages, move(doorbell_regs)))); dbgln_if(NVME_DEBUG, "NVMe: Created IO Queue with QID{}", m_queues.size()); diff --git a/Kernel/Storage/NVMe/NVMeController.h b/Kernel/Storage/NVMe/NVMeController.h index 198da902b1..4210fc5ea9 100644 --- a/Kernel/Storage/NVMe/NVMeController.h +++ b/Kernel/Storage/NVMe/NVMeController.h @@ -6,14 +6,14 @@ #pragma once -#include <AK/NonnullRefPtr.h> -#include <AK/NonnullRefPtrVector.h> #include <AK/OwnPtr.h> -#include <AK/RefPtr.h> #include <AK/Time.h> #include <AK/Tuple.h> #include <AK/Types.h> #include <Kernel/Bus/PCI/Device.h> +#include <Kernel/Library/LockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtrVector.h> #include <Kernel/Locking/Spinlock.h> #include <Kernel/Memory/TypedMapping.h> #include <Kernel/Storage/NVMe/NVMeDefinitions.h> @@ -26,10 +26,10 @@ namespace Kernel { class NVMeController : public PCI::Device , public StorageController { public: - static ErrorOr<NonnullRefPtr<NVMeController>> try_initialize(PCI::DeviceIdentifier const&, bool is_queue_polled); + static ErrorOr<NonnullLockRefPtr<NVMeController>> try_initialize(PCI::DeviceIdentifier const&, bool is_queue_polled); ErrorOr<void> initialize(bool is_queue_polled); explicit NVMeController(PCI::DeviceIdentifier const&); - RefPtr<StorageDevice> device(u32 index) const override; + LockRefPtr<StorageDevice> device(u32 index) const override; size_t devices_count() const override; protected: @@ -68,10 +68,10 @@ private: private: PCI::DeviceIdentifier m_pci_device_id; - RefPtr<NVMeQueue> m_admin_queue; - NonnullRefPtrVector<NVMeQueue> m_queues; - NonnullRefPtrVector<NVMeNameSpace> m_namespaces; - Memory::TypedMapping<volatile ControllerRegister> m_controller_regs; + LockRefPtr<NVMeQueue> m_admin_queue; + NonnullLockRefPtrVector<NVMeQueue> m_queues; + NonnullLockRefPtrVector<NVMeNameSpace> m_namespaces; + Memory::TypedMapping<ControllerRegister volatile> m_controller_regs; bool m_admin_queue_ready { false }; size_t m_device_count { 0 }; AK::Time m_ready_timeout; diff --git a/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp b/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp index 105c4a6251..310a491da6 100644 --- a/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp +++ b/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp @@ -11,7 +11,7 @@ namespace Kernel { -UNMAP_AFTER_INIT NVMeInterruptQueue::NVMeInterruptQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) +UNMAP_AFTER_INIT NVMeInterruptQueue::NVMeInterruptQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) : NVMeQueue(move(rw_dma_region), rw_dma_page, qid, q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)) , IRQHandler(irq) { diff --git a/Kernel/Storage/NVMe/NVMeInterruptQueue.h b/Kernel/Storage/NVMe/NVMeInterruptQueue.h index 9b562efb58..b69370cc66 100644 --- a/Kernel/Storage/NVMe/NVMeInterruptQueue.h +++ b/Kernel/Storage/NVMe/NVMeInterruptQueue.h @@ -13,7 +13,7 @@ namespace Kernel { class NVMeInterruptQueue : public NVMeQueue , public IRQHandler { public: - NVMeInterruptQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); + NVMeInterruptQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); void submit_sqe(NVMeSubmission& submission) override; virtual ~NVMeInterruptQueue() override {}; diff --git a/Kernel/Storage/NVMe/NVMeNameSpace.cpp b/Kernel/Storage/NVMe/NVMeNameSpace.cpp index 86f312784f..f91d157434 100644 --- a/Kernel/Storage/NVMe/NVMeNameSpace.cpp +++ b/Kernel/Storage/NVMe/NVMeNameSpace.cpp @@ -12,7 +12,7 @@ namespace Kernel { -UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<NVMeNameSpace>> NVMeNameSpace::try_create(NVMeController const& controller, NonnullRefPtrVector<NVMeQueue> queues, u8 controller_id, u16 nsid, size_t storage_size, size_t lba_size) +UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<NVMeNameSpace>> NVMeNameSpace::try_create(NVMeController const& controller, NonnullLockRefPtrVector<NVMeQueue> queues, u8 controller_id, u16 nsid, size_t storage_size, size_t lba_size) { auto minor_number = StorageManagement::generate_storage_minor_number(); auto major_number = StorageManagement::storage_type_major_number(); @@ -21,7 +21,7 @@ UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<NVMeNameSpace>> NVMeNameSpace::try_create return device; } -UNMAP_AFTER_INIT NVMeNameSpace::NVMeNameSpace(LUNAddress logical_unit_number_address, NonnullRefPtrVector<NVMeQueue> queues, size_t max_addresable_block, size_t lba_size, size_t major_number, size_t minor_number, u16 nsid, NonnullOwnPtr<KString> dev_name) +UNMAP_AFTER_INIT NVMeNameSpace::NVMeNameSpace(LUNAddress logical_unit_number_address, NonnullLockRefPtrVector<NVMeQueue> queues, size_t max_addresable_block, size_t lba_size, size_t major_number, size_t minor_number, u16 nsid, NonnullOwnPtr<KString> dev_name) : StorageDevice(logical_unit_number_address, major_number, minor_number, lba_size, max_addresable_block, move(dev_name)) , m_nsid(nsid) , m_queues(move(queues)) diff --git a/Kernel/Storage/NVMe/NVMeNameSpace.h b/Kernel/Storage/NVMe/NVMeNameSpace.h index b6df088a62..150f94172e 100644 --- a/Kernel/Storage/NVMe/NVMeNameSpace.h +++ b/Kernel/Storage/NVMe/NVMeNameSpace.h @@ -7,11 +7,11 @@ #pragma once #include "AK/kmalloc.h" -#include <AK/NonnullRefPtr.h> -#include <AK/NonnullRefPtrVector.h> #include <AK/OwnPtr.h> -#include <AK/RefPtr.h> #include <AK/Types.h> +#include <Kernel/Library/LockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtrVector.h> #include <Kernel/Locking/Spinlock.h> #include <Kernel/Storage/NVMe/NVMeDefinitions.h> #include <Kernel/Storage/NVMe/NVMeQueue.h> @@ -24,16 +24,16 @@ class NVMeNameSpace : public StorageDevice { friend class DeviceManagement; public: - static ErrorOr<NonnullRefPtr<NVMeNameSpace>> try_create(NVMeController const&, NonnullRefPtrVector<NVMeQueue> queues, u8 controller_id, u16 nsid, size_t storage_size, size_t lba_size); + static ErrorOr<NonnullLockRefPtr<NVMeNameSpace>> try_create(NVMeController const&, NonnullLockRefPtrVector<NVMeQueue> queues, u8 controller_id, u16 nsid, size_t storage_size, size_t lba_size); CommandSet command_set() const override { return CommandSet::NVMe; }; void start_request(AsyncBlockDeviceRequest& request) override; private: - NVMeNameSpace(LUNAddress, NonnullRefPtrVector<NVMeQueue> queues, size_t storage_size, size_t lba_size, size_t major_number, size_t minor_number, u16 nsid, NonnullOwnPtr<KString> early_device_name); + NVMeNameSpace(LUNAddress, NonnullLockRefPtrVector<NVMeQueue> queues, size_t storage_size, size_t lba_size, size_t major_number, size_t minor_number, u16 nsid, NonnullOwnPtr<KString> early_device_name); u16 m_nsid; - NonnullRefPtrVector<NVMeQueue> m_queues; + NonnullLockRefPtrVector<NVMeQueue> m_queues; }; } diff --git a/Kernel/Storage/NVMe/NVMePollQueue.cpp b/Kernel/Storage/NVMe/NVMePollQueue.cpp index 7219034666..fa9aec2496 100644 --- a/Kernel/Storage/NVMe/NVMePollQueue.cpp +++ b/Kernel/Storage/NVMe/NVMePollQueue.cpp @@ -10,7 +10,7 @@ #include "NVMeDefinitions.h" namespace Kernel { -UNMAP_AFTER_INIT NVMePollQueue::NVMePollQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) +UNMAP_AFTER_INIT NVMePollQueue::NVMePollQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) : NVMeQueue(move(rw_dma_region), rw_dma_page, qid, q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)) { } diff --git a/Kernel/Storage/NVMe/NVMePollQueue.h b/Kernel/Storage/NVMe/NVMePollQueue.h index 458f11c14f..8a68881309 100644 --- a/Kernel/Storage/NVMe/NVMePollQueue.h +++ b/Kernel/Storage/NVMe/NVMePollQueue.h @@ -12,7 +12,7 @@ namespace Kernel { class NVMePollQueue : public NVMeQueue { public: - NVMePollQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); + NVMePollQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs); void submit_sqe(NVMeSubmission& submission) override; virtual ~NVMePollQueue() override {}; diff --git a/Kernel/Storage/NVMe/NVMeQueue.cpp b/Kernel/Storage/NVMe/NVMeQueue.cpp index 1892f6e6f8..b160e86d57 100644 --- a/Kernel/Storage/NVMe/NVMeQueue.cpp +++ b/Kernel/Storage/NVMe/NVMeQueue.cpp @@ -13,20 +13,20 @@ #include <Kernel/Storage/NVMe/NVMePollQueue.h> namespace Kernel { -ErrorOr<NonnullRefPtr<NVMeQueue>> NVMeQueue::try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) +ErrorOr<NonnullLockRefPtr<NVMeQueue>> NVMeQueue::try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) { // Note: Allocate DMA region for RW operation. For now the requests don't exceed more than 4096 bytes (Storage device takes care of it) - RefPtr<Memory::PhysicalPage> rw_dma_page; + LockRefPtr<Memory::PhysicalPage> rw_dma_page; auto rw_dma_region = TRY(MM.allocate_dma_buffer_page("NVMe Queue Read/Write DMA"sv, Memory::Region::Access::ReadWrite, rw_dma_page)); if (!irq.has_value()) { - auto queue = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) NVMePollQueue(move(rw_dma_region), *rw_dma_page, qid, q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)))); + auto queue = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMePollQueue(move(rw_dma_region), *rw_dma_page, qid, q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)))); return queue; } - auto queue = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) NVMeInterruptQueue(move(rw_dma_region), *rw_dma_page, qid, irq.value(), q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)))); + auto queue = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMeInterruptQueue(move(rw_dma_region), *rw_dma_page, qid, irq.value(), q_depth, move(cq_dma_region), cq_dma_page, move(sq_dma_region), sq_dma_page, move(db_regs)))); return queue; } -UNMAP_AFTER_INIT NVMeQueue::NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) +UNMAP_AFTER_INIT NVMeQueue::NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<volatile DoorbellRegister> db_regs) : m_current_request(nullptr) , m_rw_dma_region(move(rw_dma_region)) , m_qid(qid) diff --git a/Kernel/Storage/NVMe/NVMeQueue.h b/Kernel/Storage/NVMe/NVMeQueue.h index aa0e3727dc..7f1a792079 100644 --- a/Kernel/Storage/NVMe/NVMeQueue.h +++ b/Kernel/Storage/NVMe/NVMeQueue.h @@ -7,13 +7,13 @@ #pragma once #include <AK/AtomicRefCounted.h> -#include <AK/NonnullRefPtr.h> -#include <AK/NonnullRefPtrVector.h> #include <AK/OwnPtr.h> -#include <AK/RefPtr.h> #include <AK/Types.h> #include <Kernel/Bus/PCI/Device.h> #include <Kernel/Interrupts/IRQHandler.h> +#include <Kernel/Library/LockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtr.h> +#include <Kernel/Library/NonnullLockRefPtrVector.h> #include <Kernel/Locking/Spinlock.h> #include <Kernel/Memory/MemoryManager.h> #include <Kernel/Memory/TypedMapping.h> @@ -29,7 +29,7 @@ struct DoorbellRegister { class AsyncBlockDeviceRequest; class NVMeQueue : public AtomicRefCounted<NVMeQueue> { public: - static ErrorOr<NonnullRefPtr<NVMeQueue>> try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs); + static ErrorOr<NonnullLockRefPtr<NVMeQueue>> try_create(u16 qid, Optional<u8> irq, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs); bool is_admin_queue() { return m_admin_queue; }; u16 submit_sync_sqe(NVMeSubmission&); void read(AsyncBlockDeviceRequest& request, u16 nsid, u64 index, u32 count); @@ -43,7 +43,7 @@ protected: { m_db_regs->sq_tail = m_sq_tail; } - NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs); + NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> cq_dma_page, OwnPtr<Memory::Region> sq_dma_region, NonnullLockRefPtrVector<Memory::PhysicalPage> sq_dma_page, Memory::TypedMapping<DoorbellRegister volatile> db_regs); private: bool cqe_available(); @@ -56,7 +56,7 @@ private: protected: Spinlock m_cq_lock { LockRank::Interrupts }; - RefPtr<AsyncBlockDeviceRequest> m_current_request; + LockRefPtr<AsyncBlockDeviceRequest> m_current_request; NonnullOwnPtr<Memory::Region> m_rw_dma_region; Spinlock m_request_lock { LockRank::None }; @@ -70,12 +70,12 @@ private: u32 m_qdepth {}; Spinlock m_sq_lock { LockRank::Interrupts }; OwnPtr<Memory::Region> m_cq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> m_cq_dma_page; + NonnullLockRefPtrVector<Memory::PhysicalPage> m_cq_dma_page; Span<NVMeSubmission> m_sqe_array; OwnPtr<Memory::Region> m_sq_dma_region; - NonnullRefPtrVector<Memory::PhysicalPage> m_sq_dma_page; + NonnullLockRefPtrVector<Memory::PhysicalPage> m_sq_dma_page; Span<NVMeCompletion> m_cqe_array; Memory::TypedMapping<DoorbellRegister volatile> m_db_regs; - NonnullRefPtr<Memory::PhysicalPage> m_rw_dma_page; + NonnullLockRefPtr<Memory::PhysicalPage> m_rw_dma_page; }; } |