From 6a691306b56ec58b2c77859e124446546f82f04a Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 19 Dec 2020 13:56:12 +0200 Subject: [PATCH] Kernel: Add a method to gather the devices count of a Storage controller Also, change device() method to be const. --- Kernel/Storage/IDEChannel.cpp | 4 ++-- Kernel/Storage/IDEChannel.h | 4 ++-- Kernel/Storage/IDEController.cpp | 12 +++++++++++- Kernel/Storage/IDEController.h | 3 ++- Kernel/Storage/StorageController.h | 3 ++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Kernel/Storage/IDEChannel.cpp b/Kernel/Storage/IDEChannel.cpp index 0bb1e41e349..6334605c2c9 100644 --- a/Kernel/Storage/IDEChannel.cpp +++ b/Kernel/Storage/IDEChannel.cpp @@ -114,11 +114,11 @@ NonnullOwnPtr IDEChannel::create(const IDEController& controller, IO return make(controller, io_group, type, force_pio); } -RefPtr IDEChannel::master_device() +RefPtr IDEChannel::master_device() const { return m_master; } -RefPtr IDEChannel::slave_device() +RefPtr IDEChannel::slave_device() const { return m_slave; } diff --git a/Kernel/Storage/IDEChannel.h b/Kernel/Storage/IDEChannel.h index ae2cfea5f32..d138a18bbac 100644 --- a/Kernel/Storage/IDEChannel.h +++ b/Kernel/Storage/IDEChannel.h @@ -108,8 +108,8 @@ public: IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio); virtual ~IDEChannel() override; - RefPtr master_device(); - RefPtr slave_device(); + RefPtr master_device() const; + RefPtr slave_device() const; virtual const char* purpose() const override { return "PATA Channel"; } diff --git a/Kernel/Storage/IDEController.cpp b/Kernel/Storage/IDEController.cpp index 00e89284ce4..0d64d8d331e 100644 --- a/Kernel/Storage/IDEController.cpp +++ b/Kernel/Storage/IDEController.cpp @@ -47,6 +47,16 @@ bool IDEController::shutdown() TODO(); } +size_t IDEController::devices_count() const +{ + size_t count = 0; + for (u32 index = 0; index < 4; index++) { + if (!device(index).is_null()) + count++; + } + return count; +} + void IDEController::start_request(const StorageDevice&, AsyncBlockDeviceRequest&) { ASSERT_NOT_REACHED(); @@ -85,7 +95,7 @@ void IDEController::initialize(bool force_pio) m_channels.append(IDEChannel::create(*this, { base_io, control_io, bus_master_base.offset(8) }, IDEChannel::ChannelType::Secondary, force_pio)); } -RefPtr IDEController::device(u32 index) +RefPtr IDEController::device(u32 index) const { switch (index) { case 0: diff --git a/Kernel/Storage/IDEController.h b/Kernel/Storage/IDEController.h index 40ab04886a4..402d1a44e32 100644 --- a/Kernel/Storage/IDEController.h +++ b/Kernel/Storage/IDEController.h @@ -45,9 +45,10 @@ public: virtual ~IDEController() override; virtual Type type() const override { return Type::IDE; } - virtual RefPtr device(u32 index) override; + virtual RefPtr device(u32 index) const override; virtual bool reset() override; virtual bool shutdown() override; + virtual size_t devices_count() const override; virtual void start_request(const StorageDevice&, AsyncBlockDeviceRequest&) override; virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override; diff --git a/Kernel/Storage/StorageController.h b/Kernel/Storage/StorageController.h index 6dba3f21fea..d01a3374a45 100644 --- a/Kernel/Storage/StorageController.h +++ b/Kernel/Storage/StorageController.h @@ -51,7 +51,8 @@ public: NVMe }; virtual Type type() const = 0; - virtual RefPtr device(u32 index) = 0; + virtual RefPtr device(u32 index) const = 0; + virtual size_t devices_count() const = 0; protected: explicit StorageController(PCI::Address address)