From ac161f6a8df83c01f6d129b7a0f43bdbc68957c3 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Thu, 18 May 2023 13:15:13 +0200 Subject: [PATCH] Kernel/NVMe: Add try_create() to NVMe{Poll|Interrupt}Queue NVMe{Poll|Interrupt}Queue don't have a try_create() method. Add one to keep it consistent with how we create objects. Also this commit is in preparation to moving any initialization related code out of the constructor. --- Kernel/Storage/NVMe/NVMeInterruptQueue.cpp | 5 +++++ Kernel/Storage/NVMe/NVMeInterruptQueue.h | 5 ++++- Kernel/Storage/NVMe/NVMePollQueue.cpp | 6 ++++++ Kernel/Storage/NVMe/NVMePollQueue.h | 5 ++++- Kernel/Storage/NVMe/NVMeQueue.cpp | 4 ++-- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp b/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp index 9b3ff53a504..cdb803d4b96 100644 --- a/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp +++ b/Kernel/Storage/NVMe/NVMeInterruptQueue.cpp @@ -11,6 +11,11 @@ namespace Kernel { +ErrorOr> NVMeInterruptQueue::try_create(PCI::Device& device, NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs) +{ + return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMeInterruptQueue(device, move(rw_dma_region), rw_dma_page, qid, irq, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)))); +} + UNMAP_AFTER_INIT NVMeInterruptQueue::NVMeInterruptQueue(PCI::Device& device, NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs) : NVMeQueue(move(rw_dma_region), rw_dma_page, qid, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)) , PCIIRQHandler(device, irq) diff --git a/Kernel/Storage/NVMe/NVMeInterruptQueue.h b/Kernel/Storage/NVMe/NVMeInterruptQueue.h index 13a8973be29..e442e6e6cf9 100644 --- a/Kernel/Storage/NVMe/NVMeInterruptQueue.h +++ b/Kernel/Storage/NVMe/NVMeInterruptQueue.h @@ -14,11 +14,14 @@ namespace Kernel { class NVMeInterruptQueue : public NVMeQueue , public PCIIRQHandler { public: - NVMeInterruptQueue(PCI::Device& device, NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); + static ErrorOr> try_create(PCI::Device& device, NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); void submit_sqe(NVMeSubmission& submission) override; virtual ~NVMeInterruptQueue() override {}; virtual StringView purpose() const override { return "NVMe"sv; }; +protected: + NVMeInterruptQueue(PCI::Device& device, NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u8 irq, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); + private: virtual void complete_current_request(u16 cmdid, u16 status) override; bool handle_irq(RegisterState const&) override; diff --git a/Kernel/Storage/NVMe/NVMePollQueue.cpp b/Kernel/Storage/NVMe/NVMePollQueue.cpp index 64e6d3ed170..4037d8276c3 100644 --- a/Kernel/Storage/NVMe/NVMePollQueue.cpp +++ b/Kernel/Storage/NVMe/NVMePollQueue.cpp @@ -10,6 +10,12 @@ #include namespace Kernel { + +ErrorOr> NVMePollQueue::try_create(NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs) +{ + return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMePollQueue(move(rw_dma_region), rw_dma_page, qid, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)))); +} + UNMAP_AFTER_INIT NVMePollQueue::NVMePollQueue(NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs) : NVMeQueue(move(rw_dma_region), rw_dma_page, qid, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)) { diff --git a/Kernel/Storage/NVMe/NVMePollQueue.h b/Kernel/Storage/NVMe/NVMePollQueue.h index 04a42f9c8a7..9df05a6e770 100644 --- a/Kernel/Storage/NVMe/NVMePollQueue.h +++ b/Kernel/Storage/NVMe/NVMePollQueue.h @@ -12,10 +12,13 @@ namespace Kernel { class NVMePollQueue : public NVMeQueue { public: - NVMePollQueue(NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); + static ErrorOr> try_create(NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); void submit_sqe(NVMeSubmission& submission) override; virtual ~NVMePollQueue() override {}; +protected: + NVMePollQueue(NonnullOwnPtr rw_dma_region, NonnullRefPtr rw_dma_page, u16 qid, u32 q_depth, OwnPtr cq_dma_region, OwnPtr sq_dma_region, Memory::TypedMapping db_regs); + private: virtual void complete_current_request(u16 cmdid, u16 status) override; }; diff --git a/Kernel/Storage/NVMe/NVMeQueue.cpp b/Kernel/Storage/NVMe/NVMeQueue.cpp index f7b5ea11f72..5f282d6a859 100644 --- a/Kernel/Storage/NVMe/NVMeQueue.cpp +++ b/Kernel/Storage/NVMe/NVMeQueue.cpp @@ -22,11 +22,11 @@ ErrorOr> NVMeQueue::try_create(NVMeController& devi return ENOMEM; if (queue_type == QueueType::Polled) { - auto queue = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMePollQueue(move(rw_dma_region), rw_dma_page.release_nonnull(), qid, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)))); + auto queue = NVMePollQueue::try_create(move(rw_dma_region), rw_dma_page.release_nonnull(), qid, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)); return queue; } - auto queue = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) NVMeInterruptQueue(device, move(rw_dma_region), rw_dma_page.release_nonnull(), qid, irq, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)))); + auto queue = NVMeInterruptQueue::try_create(device, move(rw_dma_region), rw_dma_page.release_nonnull(), qid, irq, q_depth, move(cq_dma_region), move(sq_dma_region), move(db_regs)); return queue; }